+ Reply to Thread
Results 1 to 13 of 13

Convert Text to Numeric value

  1. #1
    Forum Contributor
    Join Date
    02-16-2012
    Location
    London, England
    MS-Off Ver
    Excel mac 2011
    Posts
    238

    Convert Text to Numeric value

    Hi there,

    Wondering if it is possible to convert a string into a numeric value. The idea is that if you have a list of names, if you could add up the numeric values of the names together and hide it at the end of the list. Then if a name on the list changes, then so will that value.

    I know how to do this in C or Python, but I am rather new to the syntax of VBA.

    Kind regards

    Rob

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,054

    Re: Convert Text to Numeric value

    can numbers be duplicated?

    for example if you use CODE function you will get list:
    A = 65
    B = 66
    C = 67
    etc

    Now if you have name "BB" that would be 122. But name "AC" will also be 122. Is this what you looking for or you want something else?
    Never use Merged Cells in Excel

  3. #3
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Convert Text to Numeric value

    How do you calculate the numeric values of the name? I guess you could do something like:
    Please Login or Register  to view this content.
    Edit: Just seen Zbor's post, I think the VBA function ASC() does the same thing as the worksheet function CODE().
    Last edited by ragulduy; 05-09-2014 at 09:11 AM.

  4. #4
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Convert Text to Numeric value

    This is the value for String in "A1" in "B1".
    Please Login or Register  to view this content.
    Regards Mick

  5. #5
    Forum Contributor
    Join Date
    02-16-2012
    Location
    London, England
    MS-Off Ver
    Excel mac 2011
    Posts
    238

    Re: Convert Text to Numeric value

    Excellent, thankyou, this is exactly what I am looking for, I have a spreadsheet with say 20 employees with all dates and stuff, and I am just getting my script to check if there is a change in employee, if there is then go through some other code if not then don't bother. I am trying to avoid going through unneccesary code to speed it up as employees only change every few months from department to department, so this check will flag this up. The chances of one person leaving, then another joining with the same numeric value for his name, in my opinion, is unlikely, but I can do a simple script in matlab that will give me the odds. I just saw this as a quicker way to check this than comparing the list to see if it changed.

    I will have a bash at all of these to see which would work best and feedback what I find.

    Kind regards

    Rob

  6. #6
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Convert Text to Numeric value

    If you have two lists, one in A1:A4 and one in B1:B4, a formula like:
    =SUM(COUNTIF(A1:A4,B1:B4))=COUNTA(A1:A4)
    entered as an array formula (confirm with ctrl+shift+enter) will return true/false if the lists are the same/different

    Edit, if you need it as vba then you could probably use:
    Evaluate("=SUM(COUNTIF(A1:A4,B1:B4))=COUNTA(A1:A4)")

  7. #7
    Forum Contributor
    Join Date
    02-16-2012
    Location
    London, England
    MS-Off Ver
    Excel mac 2011
    Posts
    238

    Re: Convert Text to Numeric value

    Ok, I just tried your script MikeG, works very well, but the numbers I am getting are just too large, how could I add the individual letters together.
    So for example at the moment,
    A = 65
    AB = 6566

    How could I make
    AB = 131
    ?

    Thanks in advance.

    Rob

  8. #8
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Convert Text to Numeric value

    Try this for list in column "A" unique Codes in Column "B".
    Please Login or Register  to view this content.
    Regards Mick
    Last edited by MickG; 05-10-2014 at 05:54 AM.

  9. #9
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Convert Text to Numeric value

    Cant you just use
    =SUMPRODUCT(CODE(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)))
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  10. #10
    Forum Contributor
    Join Date
    02-16-2012
    Location
    London, England
    MS-Off Ver
    Excel mac 2011
    Posts
    238

    Re: Convert Text to Numeric value

    Thanks guys, I have lot's to work with now, very much appreciated.

  11. #11
    Forum Contributor
    Join Date
    02-16-2012
    Location
    London, England
    MS-Off Ver
    Excel mac 2011
    Posts
    238

    Re: Convert Text to Numeric value

    Ok come across another little quirk here. Martin, your formula is perfect except I can't get it to ignore blank squares which is an issue, as I can not now SUM a list of them. Is there a way to do this, I basically have a list of people that grows and shrinks so the formula is permenantly there whether the cell is full or blank, I can't find a way for Excel to ignore this.

    @ MickG, I can't see in this code where the value comes from, it is no longer asci text value, this makes my code difficult to verify as a newby programmer, could you point out the line that actually gives a number for a letter please.

    Kind regards

    Rob

  12. #12
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Convert Text to Numeric value

    =iferror(sumproduct(code(mid(a1,row(indirect("1:"&len(a1))),1))),0) ?

  13. #13
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,054

    Re: Convert Text to Numeric value

    mdw, with IFERROR you can avoid INDIRECT part, right?
    With ROW(A1:A100)
    If that would be faster

+ 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. Replies: 4
    Last Post: 02-06-2006, 03:05 AM
  2. convert text to numeric vba add-in?
    By sulmau in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 10:05 AM
  3. convert text to numeric vba add-in?
    By Ron de Bruin in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-06-2005, 06:05 AM
  4. convert text to numeric vba add-in?
    By sulmau in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 12:05 AM
  5. [SOLVED] convert text to numeric vba add-in?
    By sulmau in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 11:05 PM

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