I want to go through a column with a cells containing numbers, letters and other characters of different length, and classify in a second row sort the "template" of this cell.
Numbers should become "N", letters should become "L" and other characters should remain the same.
So e.g. if A1 contains "A35p@5" it the output in B1 should be "LNNL@N".
Here is my code so far, but it does only work for the first character. Also for other or special characters the output just continues to copy whatever is after the character. See output from my test case in Excel and VBA code below. What am I missing here?
Sub myMacro()
'Define variables
Dim char As String
For I = 1 To Range("A10").End(xlUp).Row
For J = 1 To Len(Range("A" & I))
char = Left(Range("A" & I), J)
If IsNumeric(char) Then
Range("B" & I).Value = "N"
ElseIf IsLetter(char) Then
Range("B" & I).Value = "L"
ElseIf IsSecialCharacter(char) Then
Range("B" & I).Value = char
End If
Next J
Next I
End Sub
Function IsLetter(r As String) As Boolean
If r = "" Then Exit Function
Dim x As Long
x = Asc(UCase(r))
IsLetter = (x > 64 And x < 91)
End Function
Function IsSecialCharacter(r As String) As Boolean
If r = "" Then Exit Function
Dim x As Long
x = Asc(UCase(r))
IsSecialCharacter = (x > 31 And x < 48) Or (x > 57 And x < 65) Or (x > 90 And x < 97) Or (x > 122 And x < 127)
End Function

