Hi Legends,
The code below was working but now for some reason it doesn't seem to be working. Does anyone know why this could be or how to fix it (or even a better fool-proof code?)
All the code does is: look in Cell B4 and if its contains characters like ?!,.#$%^ etc - remove these.
What I mean by not working:
-When i first wrote it a few weeks back it worked fine (both individually when pressing F8 and when executing my overall macro)
-However recently, I noticed at times it would sometimes look like its executing the code line but obviously not removing any characters (and no debug prompts) - therefore to make sure it properly finds and replaces characters, I incorporated the loop so that it does this 5 times - this seemed to have had fixed that niggly issue
-but now it just doesn't work at all - even looping 5 times or when individually pressing F8 to test if the code works it doesnt remove any of the characters - it doesnt prompt with the error debug message either
Just seems for some reason its stopped functioning even though no changes made to the code, or my windows/excel version... :-s
Any ideas to fix it would be greatly appreciated.
The code below was working but now for some reason it doesn't seem to be working. Does anyone know why this could be or how to fix it (or even a better fool-proof code?)
All the code does is: look in Cell B4 and if its contains characters like ?!,.#$%^ etc - remove these.
What I mean by not working:
-When i first wrote it a few weeks back it worked fine (both individually when pressing F8 and when executing my overall macro)
-However recently, I noticed at times it would sometimes look like its executing the code line but obviously not removing any characters (and no debug prompts) - therefore to make sure it properly finds and replaces characters, I incorporated the loop so that it does this 5 times - this seemed to have had fixed that niggly issue
-but now it just doesn't work at all - even looping 5 times or when individually pressing F8 to test if the code works it doesnt remove any of the characters - it doesnt prompt with the error debug message either
Just seems for some reason its stopped functioning even though no changes made to the code, or my windows/excel version... :-s
Any ideas to fix it would be greatly appreciated.
VBA Code:
Sub RemoveCharacters()
'Code removes following characters ...;-<>:!@#$%^&()-_+=.,~`?*/\[]{}|
Dim i As Long
Sheets("Test Sheet").Select
For i = 1 To 5
Range("B4").Replace "~*", ""
Range("B4").Replace "~?", ""
Range("B4").Replace "~~", ""
Range("B4").Replace "`", ""
Range("B4").Replace "/", ""
Range("B4").Replace "\", ""
Range("B4").Replace "[", ""
Range("B4").Replace "]", ""
Range("B4").Replace "{", ""
Range("B4").Replace "}", ""
Range("B4").Replace "|", ""
Range("B4").Replace "!", ""
Sheets("Test Sheet").Range("B4").Replace _
What:=".", Replacement:="", _
SearchOrder:=xlByColumns, MatchCase:=True
Sheets("Test Sheet").Range("B4").Replace _
What:=";", Replacement:="", _
SearchOrder:=xlByColumns, MatchCase:=True
Sheets("Test Sheet").Range("B4").Replace _
What:="-", Replacement:="", _
SearchOrder:=xlByColumns, MatchCase:=True
Sheets("Test Sheet").Range("B4").Replace _
What:="<", Replacement:="", _
SearchOrder:=xlByColumns, MatchCase:=True
Sheets("Test Sheet").Range("B4").Replace _
What:=">", Replacement:="", _
SearchOrder:=xlByColumns, MatchCase:=True
Sheets("Test Sheet").Range("B4").Replace _
What:=":", Replacement:="", _
SearchOrder:=xlByColumns, MatchCase:=True
Sheets("Test Sheet").Range("B4").Replace _
What:="!", Replacement:="", _
SearchOrder:=xlByColumns, MatchCase:=True
Sheets("Test Sheet").Range("B4").Replace _
What:="@", Replacement:="", _
SearchOrder:=xlByColumns, MatchCase:=True
Sheets("Test Sheet").Range("B4").Replace _
What:="#", Replacement:="", _
SearchOrder:=xlByColumns, MatchCase:=True
Sheets("Test Sheet").Range("B4").Replace _
What:="$", Replacement:="", _
SearchOrder:=xlByColumns, MatchCase:=True
Sheets("Test Sheet").Range("B4").Replace _
What:="%", Replacement:="", _
SearchOrder:=xlByColumns, MatchCase:=True
Sheets("Test Sheet").Range("B4").Replace _
What:="^", Replacement:="", _
SearchOrder:=xlByColumns, MatchCase:=True
Sheets("Test Sheet").Range("B4").Replace _
What:="&", Replacement:="", _
SearchOrder:=xlByColumns, MatchCase:=True
Sheets("Test Sheet").Range("B4").Replace _
What:="(", Replacement:="", _
SearchOrder:=xlByColumns, MatchCase:=True
Sheets("Test Sheet").Range("B4").Replace _
What:=")", Replacement:="", _
SearchOrder:=xlByColumns, MatchCase:=True
Sheets("Test Sheet").Range("B4").Replace _
What:="-", Replacement:="", _
SearchOrder:=xlByColumns, MatchCase:=True
Sheets("Test Sheet").Range("B4").Replace _
What:="_", Replacement:="", _
SearchOrder:=xlByColumns, MatchCase:=True
Sheets("Test Sheet").Range("B4").Replace _
What:="+", Replacement:="", _
SearchOrder:=xlByColumns, MatchCase:=True
Sheets("Test Sheet").Range("B4").Replace _
What:="=", Replacement:="", _
SearchOrder:=xlByColumns, MatchCase:=True
Sheets("Test Sheet").Range("B4").Replace _
What:=".", Replacement:="", _
SearchOrder:=xlByColumns, MatchCase:=True
Sheets("Test Sheet").Range("B4").Replace _
What:=",", Replacement:="", _
SearchOrder:=xlByColumns, MatchCase:=True
Sheets("Test Sheet").Range("B4").Replace _
What:="~", Replacement:="", _
SearchOrder:=xlByColumns, MatchCase:=True
Next i
End Sub