How to convert Excel column numbers into alphabetical characters

In Access I write data into an Excel file and need to address cells. For example I want to address the 50 th column and need to get the column address (in this example AX).

I found a solution which not proper work:
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)
   End If
   If iRemainder > 0 Then
      ConvertToLetter = ConvertToLetter & Chr(iRemainder + 64)
   End If
End Function

Open in new window

53 results in A[ instead of BA .

Is there any proper solution?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

of course you can reference cells using numbers
activesheet.cells(1,50) ' where 1 is row number and 50 is column number

also you use extract column part from this this

ActiveSheet.Cells(1, 50).Address
Of course Farwest answer is right

just to answer the question
Function ColumnLetter(ColNumber As Long) As String
    Dim lVar As Long
    Dim bVar As Byte
    Dim sVar As String

    lVar = ColNumber
        bVar = ((lVar - 1) Mod 26)
        sVar = Chr(bVar + 65) & sVar
        lVar = (lVar - bVar) \ 26
    Loop While lVar > 0
    ColumnLetter = sVar
End Function

Open in new window

this is the implementation
Public Function GetColumnName(colindex As Integer) As String
GetColumnName = Split(Cells(1, colindex).Address, "$")(1)
End Function

Public Sub test()
Debug.Print GetColumnName(10)
End Sub

Open in new window

Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

you can also use this single line of code if your column index will not exceed 701, that is not depend on worksheet reference or open sheet, and only if your column index will not exceed 701
Public Function GetColumnName(x As Integer) As String
GetColumnName = IIf(Int(x / 26) < 1, Chr(IIf(Int(x / 26) < 1, x, 1) + 64), Chr(Int(x / 26) + 64) + Chr((x - (Int(x / 26)) * 26) + 64))
End Function

Open in new window

Rory ArchibaldCommented:
Function ColLtr(ByVal iCol As Long) As String
    If iCol > 0 Then ColLtr = ColLtr((iCol - 1) \ 26) & Chr(65 + (iCol - 1) Mod 26)
End Function

Open in new window

which should cover any positive Long Integer value.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
good job @Rory
User2008Author Commented:
It is  working perfectly in Access
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.