Excel VBA – How to convert Column Number into Column Letter?

This is a function, to convert the Column in number into the Column Letter, in order to work with most Range, functions in VBA, the Column Letter will be very useful than the Column number.

e.g. Column “A” = Column number 1

Column “C” = Column number 3

Function ConvertToLetter(ByVal iCol As Integer) As String

If iCol <= 26 Then
‘ Columns A-Z
ConvertToLetter = Chr(iCol + 64)
End If

If iCol > 26 Then
‘ Column label greater than Z, going into AA…
ConvertToLetter = Chr(Int((iCol – 1) / 26) + 64) & Chr(((iCol – 1) Mod 26) + 65)
End If

End Function

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s