B
Bralyan
I found this code to increment a text string,
Function IncrementTextString(txt As String) As String
Dim L As Integer, i As Integer, c As Integer
Dim S As String
S = txt
L = Len(S)
For i = L To 1 Step -1 'go thru the string, right to left
c = Asc(Mid(S, i, 1)) 'ASCII code of the i-th character
Select Case c
Case 65 To 89, 97 To 121 'A-Y or a-y
S = Left(S, i - 1) & Chr(c + 1) & Mid(S, i + 1)
Exit For
Case 90 'Z
S = Left(S, i - 1) & "A" & Mid(S, i + 1)
Case 122 'z
S = Left(S, i - 1) & "a" & Mid(S, i + 1)
End Select
'in the last two cases, we need to continue the loop:
Next i
If i = 0 Then
IncrementTextString = String(L + 1, 65) 'grow the string
Else
IncrementTextString = S
End If
End Function
But I want to decrement the text string
i.e.
AA to Z
BB to BA
AAA to ZA
etc.. thanks
Function IncrementTextString(txt As String) As String
Dim L As Integer, i As Integer, c As Integer
Dim S As String
S = txt
L = Len(S)
For i = L To 1 Step -1 'go thru the string, right to left
c = Asc(Mid(S, i, 1)) 'ASCII code of the i-th character
Select Case c
Case 65 To 89, 97 To 121 'A-Y or a-y
S = Left(S, i - 1) & Chr(c + 1) & Mid(S, i + 1)
Exit For
Case 90 'Z
S = Left(S, i - 1) & "A" & Mid(S, i + 1)
Case 122 'z
S = Left(S, i - 1) & "a" & Mid(S, i + 1)
End Select
'in the last two cases, we need to continue the loop:
Next i
If i = 0 Then
IncrementTextString = String(L + 1, 65) 'grow the string
Else
IncrementTextString = S
End If
End Function
But I want to decrement the text string
i.e.
AA to Z
BB to BA
AAA to ZA
etc.. thanks