+ Reply to Thread
Results 1 to 7 of 7

Convert letter to Number

Hybrid View

  1. #1
    Registered User
    Join Date
    05-05-2009
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2003
    Posts
    97

    Convert letter to Number

    Is there simple function that anyone knows of (or has written) that will convert a letter to its alpha-numeric equivalent?

    For instance, A = 1, B = 2, AA = 27, etc (a = 1, b = 2, aa = 27)
    Last edited by gtmeloney; 07-23-2009 at 10:54 AM.

  2. #2
    Registered User
    Join Date
    11-11-2008
    Location
    Syracuse NY
    MS-Off Ver
    2007
    Posts
    90

    Re: Convert letter to Number

    Ran into this yesterday, no idea if it works:
    http://www.vbaexpress.com/kb/getarticle.php?kb_id=218

  3. #3
    Registered User
    Join Date
    05-05-2009
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2003
    Posts
    97

    Re: Convert letter to Number

    Thanks J.

    I learned the following trick from the link you sent:

        Dim nNum As Integer
        Dim str As String
        
        str = "d"
        
        nNum = (Range(str & "1").Column)
        
        MsgBox (nNum)
    I will wrap that in a function and be on my way.

    Thanks

  4. #4
    Registered User
    Join Date
    11-11-2008
    Location
    Syracuse NY
    MS-Off Ver
    2007
    Posts
    90

    Re: Convert letter to Number

    Whoops, ran into this too: http://exceltip.com/st/Convert_betwe...Excel/478.html

    The function below converts a number between 1 and 256 to a column reference between A and IV: 
    Function ColNo2ColRef(ColNo As Integer) As String
        If ColNo < 1 Or ColNo > 256 Then
            ColNo2ColRef = "#VALUE!"
            Exit Function
        End If
        ColNo2ColRef = Cells(1, ColNo).Address(True, False, xlA1)
        ColNo2ColRef = Left(ColNo2ColRef, InStr(1, ColNo2ColRef, "$") - 1)
    End Function
    The function below converts a column reference (A - IV) to a column number between 1 and 256: 
    Function ColRef2ColNo(ColRef As String) As Integer
        ColRef2ColNo = 0
        On Error Resume Next
        ColRef2ColNo = Range(ColRef & "1").Column
    End Function
    Last edited by jrussell; 07-23-2009 at 10:56 AM.

  5. #5
    Registered User
    Join Date
    05-05-2009
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2003
    Posts
    97

    Re: Convert letter to Number

    Thanks again J.

  6. #6
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Re: Convert letter to Number

    Incidently why are you wanting / needing to do this? If it is for referencing columns it can be done in it's numeric format...
    If you find the response helpful please click the scales in the blue bar above and rate it
    If you don't like the response, don't bother with the scales, they are not for you

  7. #7
    Registered User
    Join Date
    05-05-2009
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2003
    Posts
    97

    Re: Convert letter to Number

    I store several column letters to display to the user, and now I need to take that list of Column letters and set a combobox according to the corresponding column number.

    So if the column is A, I need to select the 0th index in the combobox, if the column is D, I need to select the 3rd index. Hence my need for the number conversion

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1