Option Explicit
Option Compare Text
Const strAlphabet As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZA"
Sub incrementLettersAndNumbers()
Dim iStrLength As Integer, iCharacter As Integer, iLoop As Integer
Dim cl As Range, strThis As String, i As Integer
Dim arrText() As String
For Each cl In Selection
' set new string if it exists
If cl <> "" Then
strThis = cl.Value ' set next text string to work with
iStrLength = Len(strThis) ' get text length
iCharacter = iStrLength ' start with last character
' load text strings into an array
ReDim arrText(1 To iStrLength) As String
For i = 1 To iStrLength
arrText(i) = Mid(strThis, i, 1)
Next i
' don't increment this cell
GoTo nextCL
End If
' attempt to increment non-blanks
If strThis <> "" Then
' attempt to increment every text character
For iLoop = iStrLength To 1 Step -1
arrText(iLoop) = incrementCharacter(arrText(iLoop)) ' increment next character
If arrText(iLoop) <> "A" And arrText(iLoop) <> "0" Then Exit For ' escape process if character didn't "loop" i.e. Z to A or 9 to 0
Next iLoop
' write results back to cell
cl = Join(arrText, "")
End If
nextCL:
Next cl
End Sub
Function incrementCharacter(str As String) As String
' this function uplifts numbers and letters. ANY other character becomes #
Dim iStr As Integer: iStr = InStr(1, strAlphabet, str)
If iStr > 0 Then
incrementCharacter = Mid(strAlphabet, iStr + 1, 1)
ElseIf IsNumeric(str) Then
incrementCharacter = Right(str + 1, 1)
Else
incrementCharacter = "#"
End If
End Function