Consider the following VBA Function:
Sub RemoveLetters()
Application.ScreenUpdating = False
Dim str As String: str = "abcdefghijklmnopqrstuvwxyz0123456789 "
Dim ltr As String
For i = 1 To 37
ltr = Mid(str, i, 1)
Sheet9.Range("A2:A1800").Replace _
What:=ltr, Replacement:="", MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
Next
Application.ScreenUpdating = True
End Sub
This function gets rid of all letter and number characters in a given string. However, the error I encounter is that whenever a string begins with a non-letter, non-number string it fails to execute on that string and does not execute on any further strings. That is, running into such a string stops the execution. Is there an obvious reason why this is happening? How might I modify this code to fix it?
$asdand it worked. What are examples of these strings that "begins with a non-letter, non-number"?[email protected]. The macro left'@.on my cell, which should be correct, as@functions the same way as=,-, etc in that they can start formulas, so Excel forces them to string format by adding'. (Try@SUM. It's the same as=SUM.) I don't see why this should throw an error, really, on your end. What happens if you addOn Error Resume Nextbefore theFor i=...line?@as it reads as a formula. Check the formula bar while this cell on your end is highlighted. What does it show? Just@stringor'@string? I bet it starts with'. That will stop the macro, based on my tests.