MITHU
MITHU

Reputation: 154

How to increment alphabetic characters from AA to ZZ?

I'm trying to increment alphabetic characters from AA to ZZ.

The one I created is capable of incrementing alphabetic characters from A to Z.

I only need from AA to ZZ. I will use them as search terms in a webpage to populate results.

Sub GetAlphabets()
    Dim myvar$, I&
        
    For I = 65 To 90
        myvar = Chr(I)
        Debug.Print myvar
    Next I
End Sub

Upvotes: 0

Views: 562

Answers (2)

T.M.
T.M.

Reputation: 9948

Alternative via column addresses

The following example call needs only one loop to show all combinations:

Sub AA2ZZ()
Dim i As Long
For i = 1 To 27 * 26             ' i.e. 1 * 26 for single chars, 26 * 26 for pairs
    Debug.Print i, Split((Columns(i).Address(, 0)), ":")(0)
Next i
End Sub

Upvotes: 1

Warcupine
Warcupine

Reputation: 4640

Use a second loop

Sub GetAlphabets()
    Dim myvar As String
    Dim I As Long, J As Long
    
    For I = 65 To 90
        For J = 65 To 90
            myvar = Chr(I) & Chr(J)
            Debug.Print myvar
        Next J
    Next I
End Sub

Upvotes: 3

Related Questions