Best way to increment by letters after number 26

gravanoc

Active Member
Joined
Oct 20, 2015
Messages
348
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
A window designer wants to number each window and use letters for each panel in that window. For example, he wants 4 windows: Window #1 has 2 panels, #2 has 4, #3 has 4, #4 has 8. This would produce the following series:

1A, 1B, 2A, 2B, 2C, 2D, 3A, 3B, 3C, 3D, 4A, 4B, 4C, 4D, 4E, 4F, 4G, 4H.

Though it's unlikely to exceed 26 panels, or even multiples of 26, I still want to be prepared for such. Using VBA to generate the number & letter combinations as follows:

VBA Code:
For i = 0 To windowRng.Rows.count - 1
    
            panelCount(i) = panelRng.Cells(i + 1, 1).Value
        
            For j = 0 To panelCount(i) - 1
            
                  quot = WorksheetFunction.RoundDown(j / 26, 0)
                  Debug.Assert (quot = 0)
                  
                  prodRng.Cells(j + 1, 1).Value = i + 1
                  For x= 0 To quot
                  
                    prodRng.Cells(j + 1, 2).Value = prodRng.Cells(j + 1, 2).Value & Chr(65 + (j Mod 26))
                
                Next x

                ' More code not shown

             Next j

Next i

The problem with the above code is that it will not know to increment the subsequent concatenated letters, and they will subsequently be AA, BB, CC, or AAA, BBB, CCC, and so on. The desired pattern would be AA, AB, AC, etc. Please assist me in that regard, thank you.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Here's a UDF which can generate the letter sequence Excel uses to label columns. Example below shows first 52 letters. Sequence covers "A" through "XFD".
Book4
AB
1Sequence No.Letter(s)
21A
32B
43C
54D
65E
76F
87G
98H
109I
1110J
1211K
1312L
1413M
1514N
1615O
1716P
1817Q
1918R
2019S
2120T
2221U
2322V
2423W
2524X
2625Y
2726Z
2827AA
2928AB
3029AC
3130AD
3231AE
3332AF
3433AG
3534AH
3635AI
3736AJ
3837AK
3938AL
4039AM
4140AN
4241AO
4342AP
4443AQ
4544AR
4645AS
4746AT
4847AU
4948AV
5049AW
5150AX
5251AY
5352AZ
3
Cell Formulas
RangeFormula
A2:A101A2=SEQUENCE(100,1,1,1)
B2:B53B2=PERSONAL.XLSB!colno2colref(A2)
Dynamic array formulas.

VBA Code:
Function ColNo2ColRef(ColNo As Integer) As String
'Returns column letter reference (e.g. AAB) when col number is the argument
    If ColNo < 1 Or ColNo > Cells.Columns.Count Then
        ColNo2ColRef = "#VALUE!"
        Exit Function
    End If
    ColNo2ColRef = Split(Cells(1, ColNo).Address, "$")(1)
End Function
 
Upvote 0
Solution
This will return columns letters from A to FXSHRXW:

VBA Code:
Function ColLtr(ByVal iCol As Long) As String
  ' shg 2012
  ' Good for any positive Long
  If iCol > 0 Then ColLtr = ColLtr((iCol - 1) \ 26) & Chr(65 + (iCol - 1) Mod 26)
End Function
 
Upvote 0

Forum statistics

Threads
1,215,004
Messages
6,122,656
Members
449,091
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top