+ Reply to Thread
Results 1 to 5 of 5

Convert column of strings to number

  1. #1
    Registered User
    Join Date
    08-19-2016
    Location
    New York
    MS-Off Ver
    2013
    Posts
    4

    Convert column of strings to number

    Hi!

    I have a column of strings (animal names) and I want to convert the names into numbers (cow-> 1, zebra->3). The ordering of the numbers needs to be set by me- meaning, the names can't just be set to numbers in an arbitrary order, cow must be 1 and zebra must be 3 (sample file attached). Some of the strings contain hypens, I'm not sure if that affects anything, just letting you know.

    Technically, I could do a Case Statement but in the full file I have over 30 names, so i didn't feel that writing 30 cases was so efficient...

    Please let me know if you have any suggestions about the best way to do this.

    Thanks so much!
    Attached Files Attached Files

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,853

    Re: Convert column of strings to number

    In C2, dragged down:

    =VLOOKUP(A2,$F$2:$G$6,2,0)

    Please give an example of strings with hyphens so that we can tweak to accommodate.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    08-19-2016
    Location
    New York
    MS-Off Ver
    2013
    Posts
    4

    Re: Convert column of strings to number

    Wow! I didn't know it was that simple. Thank you so much!! I tried it with the hyphen names and it works great!

  4. #4
    Valued Forum Contributor loginjmor's Avatar
    Join Date
    01-31-2013
    Location
    Cedar Rapids, Iowa
    MS-Off Ver
    Excel 2013
    Posts
    1,073

    Re: Convert column of strings to number

    Hi -

    AliGW's formula should work, but your list in column F needs to be sorted alphabetically otherwise you may get errors or wrong numbers assigned to column C.
    ____________________________________________
    If this has solved your problem, please edit the thread title to add the word [SOLVED] at the beginning. You can do this by
    -Go to the top of the first post
    -Select Thread Tools
    -Select Mark thread as Solved

    If I have been particularly helpful, please "bump" my reputation by pressing the small star in the lower left corner of my post.

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,853

    Re: Convert column of strings to number

    Glad to have helped.

    @ Loginjmor - as this is an exact match (0 or FALSE), the lookup table does not need to be arranged alphabetically. It is only with approximate matches (1 or TRUE) that the order of the lookup table matters.
    Last edited by AliGW; 08-20-2016 at 03:19 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. [SOLVED] Determine last number in a column that contains numbers, and strings
    By anakaine in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 05-21-2015, 12:21 AM
  2. Match multiple repeating strings in a column and output the row number
    By anilsen0711 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-02-2013, 09:12 AM
  3. Replies: 2
    Last Post: 03-07-2013, 02:34 AM
  4. [SOLVED] VBA to convert 3 and 4 number strings into time with a colon
    By BWP in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-05-2013, 04:13 PM
  5. Replies: 5
    Last Post: 02-15-2012, 09:57 AM
  6. Convert ASCII Character strings into HEX Strings
    By Chris Mathers in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-13-2010, 12:25 PM
  7. Convert text strings to a code or number
    By MaxNY23 in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 03-23-2006, 06:50 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