I would like to be able to loop through a range of cells and pass each cell into a function, that modifies its text and returns it. However, I can't get the below code to work as intended.
Any suggestions?
For Each cell In Worksheets("test").Range("A2:A" & LstRw)
cell.Value = cleanCell(cell)
Next cell
Public Function cleanCell(cell As Range) As Variant
If InStr(cell.Value, "US") > 0 Then
If InStr(cell.Value, "US Test") > 0 Then
Else
cell = Replace(cell.Value, " US", " US Test")
End If
End If
End Function
cleanCell = cell
beforeEnd Function
? – JohnSUNcleanCell = Replace(cell.Value, " US", " US Test")
instead ofcell = Replace(cell.Value, " US", " US Test")
.cell
is passedbyRef
. – FaneDuru