Increment Letter in a String
Hi manish -
The code below will increment the index letters in your variable "char" up
to "ZZ", the maximum for a two-letter index:
Select Case Len(char)
Case 1 'char is one letter
If UCase(char) = "Z" Then
CellOfInterest.Value = "AA"
Else
CellOfInterest.Value = Chr(Asc(char) + 1)
End If
Case 2 'char is two letters
If Right(char, 1) = "Z" Then
CellOfInterest.Value = Chr(Asc(Left(char, 1)) + 1) & "A"
Else
CellOfInterest.Value = Left(char, 1) & Chr(Asc(Right(char, 1)) +
1)
End If
End Select
----
Jay
"manish" wrote:
Hi,
I am sorry if it is repost. I am relatively new to macros. I want to
increment letter in a string present in a cell. If the cell value is
"A" I want to make it "B" etc. However, if the cell value is "Z", I
want to change it to "AA". If it is "AA", it should change to "AB" and
so on. I wrote following code for increment letters:
NextIndex = Asc(char) + 1
CellOfInterest.Value = Chr(NextIndex)
Above code changes A to B, B to C and so on. However, it does not
change Z to AA. It just gives me next ASCII value ([). Is there any
way to make this happen?
Any help would be greatly appreciated!
|