This article discusses how to use the Microsoft Visual Basic
for Applications (VBA) function in Microsoft Excel to convert column numbers
into their corresponding alphabetical character designator for the same
For example, the column number 30 is converted into the
equivalent alphabetical characters "AD".
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
function works by using the following algorithm:
- Divide the column number by 27, and then put the resulting
integer in the variable "i".
- Subtract the column number from "i" multiplied by 26, and
then put the result in the variable "j".
- Convert the integer values into their corresponding
alphabetical characters, "i" and "j" will range from 0 to 26 respectively.
For example: The column number is 30.
- The column number is divided by 27: 30 / 27 = 1.1111,
rounded down by the Int function to "1".
i = 1
- Next Column number - (i * 26) = 30 -(1 * 26) = 30 - 26 = 4.
j = 4
- Convert the values to alphabetical characters separately,
i = 1 = "A"
j = 4 = "D"
- Combined together, they form the column designator
The following VBA function is just one way to convert column
number values into their equivalent alphabetical characters:
Function ConvertToLetter(iCol As Integer) As String
Dim iAlpha As Integer
Dim iRemainder As Integer
iAlpha = Int(iCol / 27)
iRemainder = iCol - (iAlpha * 26)
If iAlpha > 0 Then
ConvertToLetter = Chr(iAlpha + 64)
If iRemainder > 0 Then
ConvertToLetter = ConvertToLetter & Chr(iRemainder + 64)
This function only converts integers that are passed to it into
their equivalent alphanumeric text character. It does not change the appearance
of the column or the row headings on the physical worksheet.
Article ID: 833402 - Last Review: September 19, 2011 - Revision: 5.0
- Microsoft Office Excel 2007
- Microsoft Excel 2002 Standard Edition
- Microsoft Excel 2000 Standard Edition
- Microsoft Excel 97 Standard Edition
|kbcodesnippet kbcode kbhowto KB833402|