Convert Excel Column Number into Column Name

Posted on the October 29th, 2008 under Workbook and Worksheet by Poer @ Excel VBA/Macro

Converting Excel column number into column name, for example 1 into A or 52 into AZ, is needed occasionally, and the following function will do the convertion for us.

Function Number2Char(ByVal vNumber)
    Dim iDiv As Double, iMod As Integer
    If vNumber < 1 Then Exit Function

    iDiv = vNumber
    While iDiv > 26
        iMod = iDiv Mod 26
        If iMod = 0 Then
            iMod = 26
            iDiv = iDiv - 1
        End If
        Number2Char = Chr(64 + iMod) & Number2Char
        iDiv = iDiv  26
    Wend

    Number2Char = Chr(64 + iDiv) & Number2Char
End Function

FIN.

Related Entries

External Resources

Tagged with:

9 Responses to 'Convert Excel Column Number into Column Name'

  1. November 27, 2008 at 9:49 pm
    Andre Eugenio
  2. November 30, 2008 at 11:31 pm
    admin
  3. February 4, 2009 at 6:34 pm
    Stan Scott
  4. February 4, 2009 at 8:00 pm
    Poer
  5. March 12, 2009 at 5:43 am
    zung
  6. March 12, 2009 at 1:38 pm
    diskedit
  7. June 15, 2009 at 11:11 am
    hwsris
  8. June 16, 2009 at 10:21 am
    GarykPatton
  9. June 16, 2009 at 11:22 am
    Excel VBA Macro

Leave a Reply




XHTML:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
SYNTAX HIGHLIGHTER:
Place your VBA code between <pre> tags like this <pre class="brush:vb"> sub vba() ... end sub </pre>.