Sub cleanup()
strX = ""
For i = 1 To Cells(65536, "C").End(xlUp).Row
For k = 1 To Len(Range("C" & i))
'MsgBox (Mid(Range("C" & i), k, 1))
If (Asc(Mid(Range("C" & i), k, 1)) >= 65 And Asc(Mid(Range("C" & i), k, 1)) <= 90) Or _
(Asc(Mid(Range("C" & i), k, 1)) >= 97 And Asc(Mid(Range("C" & i), k, 1)) <= 122) Then
strX = strX & Mid(Range("C" & i), k, 1)
End If
Next k
Range("C" & i) = strX
strX = ""
Next
End Sub
Function bb(ByVal target As Range) As String
'declare variables
Dim i As Long
Dim str1 As String
'work through the 'target' string, character by character
For i = 1 To Len(target)
'convert each character to its Ascii value
Select Case Asc(Mid(target, i, 1))
'if the Ascii value is between 65 and 90 (A-Z) then add it to the string str1
Case 65 To 90
str1 = str1 & Mid(target, i, 1)
'if the Ascii value is between 97 and 122 (a-z) then add it to the string str1
Case 97 To 122
str1 = str1 & Mid(target, i, 1)
End Select
Next i
'make bb equal to str1
bb = str1
End Function
ASKER
ASKER
Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.
TRUSTED BY
ASKER
I chose to use you code (as it suited my limited VBA ability).
However, it crashes at the line;
Mid(ws2.Range("C" & i), k, 1) = "" ;
"Variable required - can't assign to this expression".
Any thought?
I guess it is saying that you can't assign a value to the middle of a string?? Is that right? What would be the syntax to simply replace the character with a "" ??
For k = 1 To Len(ws2.Range("C" & i))
If (Asc(Mid(ws2.Range("C" & i), k, 1)) >= 65 And Asc(Mid(ws2.Range("C" & i), k, 1)) <= 90) Or _
(Asc(Mid(ws2.Range("C" & i), k, 1)) >= 97 And Asc(Mid(ws2.Range("C" & i), k, 1)) <= 122) Or _
(Asc(Mid(ws2.Range("C" & i), k, 1))) = 32 Then
Else
Mid(ws2.Range("C" & i), k, 1) = ""
End If
Next k