Number to Letters

Excel can use numbers or letters to designate a column. The first cell in a work sheet can be addressed by Cells(1,1).Select or by range("A1").Select. The numeric column designation must be converted to a character to accommodate some VBA functions. Similarly, the character column designation must be converted to a number. I created two macros Number_To_Letters() and Letters_To_Number() to assist in the conversion.

When the character column designator is required, you can select the next column by converting from character to numeric, adding the nummeric value by one, and converting the numeric value to character.

SAS Fifth Dimension Macro-Number to Letters

Review the following code, copy it to Excel and execute it.

Function NUMBER_TO_LETTERS(ByVal COLUMN_NUMBER)
'   1378 LAST VALID NUMBER AZZ
    NUMBER_TO_LETTERS = ""
    If COLUMN_NUMBER = "" Then GoTo ENDIT
    LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    COLS = Val(COLUMN_NUMBER)
    If COLS > (26 * 27) Then
       COLS = COLS - (26 * 26)
       NUMBER_TO_LETTERS = "A"
    End If
    For III = 1 To 26
        II = 27 - III
        If COLS > (26 * II) Then
           COLS = COLS - (26 * II)
           NUMBER_TO_LETTERS = NUMBER_TO_LETTERS & _ 
                               Mid(LETTERS, II, 1)
           GoTo SKIPIT
        End If
    Next
SKIPIT:
    NUMBER_TO_LETTERS = NUMBER_TO_LETTERS & Chr(64 + COLS)
ENDIT:
End Function