Sub clean()
Dim x As Long, lastrow As Long
Dim ws As Worksheet
Dim CleanAry
Set ws = ThisWorkbook.Sheets("Sheet1")
'copy Column B to C
'Range("B1:B1048576").Copy Destination:=ws.Range("C1:C1048576")
'array for clean up
CleanAry = Array("..", "__")
lastrow = ws.Range("C1048576").End(xlUp).Row
For Each cel In Range("C1:C" & lastrow)
For i = LBound(CleanAry) To UBound(CleanAry)
cel = cel.Replace(What:=CleanAry(i), _
Replacement:=".", _
Lookat:=xlPart, _
SearchOrder:=xlByRows, _
MatchCase:=False)
Next i
Next cel
End Sub
I am trying to create an array of string combinations that will parse through a particular column and remove those string combinations from the existing strings in the cells.
However, my code only seems to work when I have one string in my array, and not when I add additional strings. I get the error :
"object required" for the "cel=..." section.
Haven't really coded in VBA consistently. Do help me figure out what is going wrong.
Range.Replacemethod returns a boolean. Don't use your target cell to catch it since you need the value in target cell.cel.Value = Replace(cel.Value, CleanAry(i), ".")