Hi everyone,
I have a VBA code puzzle to solve.
I want to reverse an alphanumeric string, but reverse only letters and leave digits where they are.
So for example:
abc123dfg ---> gfd123cba
451ubno98p ---> 451ponb98u
egc88rtv972nq100 ---> qnv88trc972ge100
Do you have any ideas?
Probably I must use nested loop. I came with this idea, but it's not working perfectly:
I have a VBA code puzzle to solve.
I want to reverse an alphanumeric string, but reverse only letters and leave digits where they are.
So for example:
abc123dfg ---> gfd123cba
451ubno98p ---> 451ponb98u
egc88rtv972nq100 ---> qnv88trc972ge100
Do you have any ideas?
Probably I must use nested loop. I came with this idea, but it's not working perfectly:
Code:
Text = ThisWorkbook.Sheets(1).Range("L2")
lenght = Len(Text)
For x = 0 To lenght - 1
signfromend = Mid(Text, (lenght - x), 1)
If Not IsNumeric(signfromend) Then
For y = x + 1 To lenght
signfromstart = Mid(Text, y, 1)
If Not IsNumeric(signfromstart) Then
reversedText = reversedText & Mid(Text, (lenght - x), 1)
Exit For
Else
reversedText = reversedText & signfromstart
Exit For
End If
x = x + 1
Next
Else
reversedText = reversedText & signfromend
End If
Next