Hi all,
I am updating an old macro and trying to use the replace function instead of two nested loops that process every character in the columns to remove all spaces, commas and dashes in the strings (addresses). My macro runs but does not replace anything. At the moment, I can get neither approach to work. Any help or suggestions is appreciated!
New:
original:
I am updating an old macro and trying to use the replace function instead of two nested loops that process every character in the columns to remove all spaces, commas and dashes in the strings (addresses). My macro runs but does not replace anything. At the moment, I can get neither approach to work. Any help or suggestions is appreciated!
New:
Code:
i = 3
Do Until i = lastrowSh3 + 1
mainSh3.Range("C" & i).Value = Replace(mainSh3.Range("C" & i).Value, " ", "")
mainSh3.Range("C" & i).Value = Replace(mainSh3.Range("C" & i).Value, "-", "")
mainSh3.Range("C" & i).Value = Replace(mainSh3.Range("C" & i).Value, ",", "")
If mainSh3.Range("C" & i) = 0 Then mainSh3.Range("D" & i).Value = ""
mainSh3.Range("D" & i).Value = Replace(mainSh3.Range("D" & i).Value, " ", "")
mainSh3.Range("D" & i).Value = Replace(mainSh3.Range("D" & i).Value, "-", "")
mainSh3.Range("D" & i).Value = Replace(mainSh3.Range("D" & i).Value, ",", "")
i = i + 1
Loop
original:
Code:
remove extra characters
i = 3
Do Until i = lastrowSh3 + 1
strString = mainSh3.Range("C" & i).Value
strOut = ""
If IsError(strString) Then GoTo SkipCell
For lngLoop = 1 To Len(strString)
If (Mid(strString, lngLoop, 1) <> " ") And (Mid(strString, lngLoop, 1) <> "-") And (Mid(strString, lngLoop, 1) <> ",") Then
strOut = strOut & Mid(strString, lngLoop, 1)
End If
Next
mainSh3.Range("C" & i).Value = strOut
If mainSh3.Range("C" & i) = 0 Then mainSh3.Range("D" & i).Value = ""
SkipCell:
i = i + 1
Loop
i = 2
Do Until i = lastrowSh3 + 1
strString = mainSh3.Range("D" & i).Value
strOut = ""
If IsError(strString) Then GoTo SkipCell2
For lngLoop = 1 To Len(strString)
If (Mid(strString, lngLoop, 1) <> " ") And (Mid(strString, lngLoop, 1) <> "-") And (Mid(strString, lngLoop, 1) <> ",") Then
strOut = strOut & Mid(strString, lngLoop, 1)
End If
Next
mainSh3.Range("D" & i).Value = strOut
If mainSh3.Range("D" & i) = 0 Then mainSh3.Range("D" & i).Value = ""
SkipCell2:
i = i + 1
Loop