# Thread: Incrementing Letters

1. Registered User
Join Date
Oct 2002
Posts
61

## Unanswered: Incrementing Letters

Does anyone have an easier way of incrementing letters?

A. Some Text
B. Some Text
C. etc.......

I am currently using the following:
Dim A, B, Letter

B = 41 'ASCII Capital 'A'

Letter = B + A
Chr\$(Letter)
'Use the letter here
A = A + 1

As you noticed this procudure only works for 26 levels. I can't seem to figure out how to double the letters i.e., AA, AB,CD, etc.

Any suggestions?

2. Registered User
Join Date
Oct 2001
Location
Chicago
Posts
440
Here's one way -
Add another variable to be used as a counter - increment when the other counter increments by >26. Use a case statement or a procedure to build your sting.

Demo code below loops through 78 x to build string to ZZZ

Matt

Dim intCharCode, intLetterCount As Integer
Dim i As Integer ' used to loop for demo...

intCharCode = 65 ' Set to "A"...
intLetterCount = 1

' Loop through this code 78 times so we can build three up to three chars
For i = 1 To 78

' Call the BuildString function passing the character count and the Character Code
Debug.Print BuildString(intLetterCount, Chr\$(intCharCode))

' If the character code is 91 then reset to 65
' and increment the intLetterCount variable by one...
If intCharCode = 90 Then
intCharCode = 65
intLetterCount = intLetterCount + 1
Else
' Increment the character code...
intCharCode = intCharCode + 1
End If

Next i

Public Function BuildString(intLetterCount As Integer, strChar As String) As String
Dim i As Integer
Dim strTemp As String

' Loop and build the string...
For i = 1 To intLetterCount
strTemp = strTemp & strChar
Next i

' Return value...
BuildString = strTemp

End Function

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•