Sub Removecomma()
Range("R2:R100").Replace What:=",", Replacement:=" ", LookAt:=xlWhole, _
SearchOrder:=xlByColumns, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End Sub
I am trying to remove all comma in Column R, but this code is not working, how can I do this?
Note that "not working" is a useless error description.
Also R2:R100
refers not to column R but only to row 2 to 100 in column R therefore the replace method will only apply to rows 2 to 100 in column R. So if you want to apply the replacement to the entire column R you need either to use Range("R:R")
or Columns("R")
.
Also I highly recommend to specify in which worksheet this range or column is. Otherwise Excel guesses and it might guess wrong: ThisWorkbook.Worksheets("Sheet1").Range("R:R")…
Finally you set LookAt:=xlWhole
that means the whole cell content has to be a comma (and nothing else in it) to be replaced with a space Replacement:=" "
.
Check out the documentation of the Range.Replace method to choose the correct value for the LookAt:=
parameter ( XlLookAt enumeration ).
Note that this code still does not remove the comma but replace the comma with a space. To remove it you must change Replacement:=" "
into Replacement:=""
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.