+ Reply to Thread
Results 1 to 14 of 14

how to convert letter to number .

  1. #1
    Forum Contributor choy96's Avatar
    Join Date
    03-19-2010
    Location
    singapore
    MS-Off Ver
    Excel 2019
    Posts
    187

    how to convert letter to number .

    how to convert the letter to number ?
    example :
    A=1, B=2, C=3, D=4, E=5
    When i key in cdba , it will show 3421

    thanks in advance.

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: how to convert letter to number .

    Have you tried to "reverse" the suggestion from your other (similar-but-opposite) thread?
    http://www.excelforum.com/excel-form...-alphabet.html
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: how to convert letter to number .

    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)

    Please Login or Register  to view this content.
    In A1 Cell

    zqa


    In B1 Cell

    =GetVal(A1)


    Result will be 26171


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  4. #4
    Forum Contributor lancer102rus's Avatar
    Join Date
    04-02-2014
    Location
    Ufa
    MS-Off Ver
    Excel 2010, 2013
    Posts
    252

    Re: how to convert letter to number .

    A little bit shorter function
    Please Login or Register  to view this content.

  5. #5
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: how to convert letter to number .

    Hi lancer102rus,

    Nice approach

    Cells(1, Mid(v.Text, i, 1)).Column

    But it will throw some errors when the input data is not a column reference

    Like

    58a%

    The result will be #VALUE!

  6. #6
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: how to convert letter to number .

    Hi,

    unless a delimiter is used which states that zqa means three columns (couldnīt it mean zq and a as well)? Same is to be mentioned for the output as I would rather prefer to see a relation between input and itīs output (just my bad taste in order to follow what means what).

    Ciao,
    Holger
    Last edited by HaHoBe; 09-10-2014 at 12:56 AM.
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  7. #7
    Forum Contributor lancer102rus's Avatar
    Join Date
    04-02-2014
    Location
    Ufa
    MS-Off Ver
    Excel 2010, 2013
    Posts
    252

    Re: how to convert letter to number .

    Hi Sixthsense!
    Of course working with exceptions is taking more time that the code itself. But TS said "how to convert the letter to number" and I took it as an axiom :-)

  8. #8
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: how to convert letter to number .

    Quote Originally Posted by HaHoBe View Post
    unless a delimiter is used which states that zqa means three columns
    Hm... Yes I thought about it while writing the code but OP have not used any delimiter in the example. So I kept it as it is and waiting to get the OP's comment for further developments

  9. #9
    Forum Contributor choy96's Avatar
    Join Date
    03-19-2010
    Location
    singapore
    MS-Off Ver
    Excel 2019
    Posts
    187

    Re: how to convert letter to number .

    i wrote like this

    Function GetVal(v As Variant) As String
    Dim iChr As Integer, sRes As String

    If TypeName(v) = "Range" Then v = v.Cells(1).Value

    For a = 1 To Len(v)
    iChr = Asc(UCase(Mid(v, i, 1)))
    If iChr > 64 And iChr < 91 Then sRes = sRes & (iChr - 64)
    Next a
    For b = 1 To Len(v)
    iChr = Asc(UCase(Mid(v, i, 1)))
    If iChr > 64 And iChr < 91 Then sRes = sRes & (iChr - 64)
    Next b

    GetVal = sRes

    End Function


    it is wrong ?

  10. #10
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: how to convert letter to number .

    Quote Originally Posted by choy96 View Post
    For a = 1 To Len(v)
    For b = 1 To Len(v)
    What you are trying to do with a b loop?

  11. #11
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: how to convert letter to number .

    Quote Originally Posted by lancer102rus View Post
    Of course working with exceptions is taking more time
    Just wanted to bring it to your notice so that you may use error handlers to avoid such data's

  12. #12
    Forum Contributor choy96's Avatar
    Join Date
    03-19-2010
    Location
    singapore
    MS-Off Ver
    Excel 2019
    Posts
    187

    Re: how to convert letter to number .

    I want my key in have any letter it will be convert to number. sometime the letter have not i set it will be not convert it.
    example :
    B=1 , C=2 , D=3 , F=4 , G=5
    BCF summer , it will be 124 summer.

    Please guide me on the more convert letter in VBA because i have no idea about VBA. if you just give me 1 letter VBA, i will not know how to continue the 2nd letter.

    Thanks in advance.

  13. #13
    Forum Contributor choy96's Avatar
    Join Date
    03-19-2010
    Location
    singapore
    MS-Off Ver
    Excel 2019
    Posts
    187

    Re: how to convert letter to number .

    sorry Sixthsense , i should be
    For a = 1 To Len(v)
    For b = 2 To Len(v)

    Currently i need the VBA for above .
    example :
    B=1 , C=2 , D=3 , F=4 , G=5
    BCF summer , it will be 124 summer.
    Last edited by choy96; 09-12-2014 at 03:50 AM.

  14. #14
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: how to convert letter to number .

    Modified Sixthsense's code. Seems like you only want to convert some letters. You can add in more "conversions" to be done to the v2 array.

    Please Login or Register  to view this content.
    Last edited by millz; 09-12-2014 at 04:24 AM.
    多么想要告诉你 我好喜欢你

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Convert number into letter, it is possible?
    By Exxcel Noob in forum Excel General
    Replies: 7
    Last Post: 05-02-2012, 05:24 PM
  2. Excel 2007 : Convert a letter to a number
    By CamnJane in forum Excel General
    Replies: 3
    Last Post: 10-25-2011, 10:52 PM
  3. Convert letter to Number
    By gtmeloney in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-23-2009, 11:10 AM
  4. Convert column number to letter
    By gtmeloney in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-08-2009, 11:13 AM
  5. How do I convert a given number into a letter?
    By vortex0001 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 09-08-2005, 06:05 AM

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