+ Reply to Thread
Results 1 to 14 of 14

Taking an integer out of a string

  1. #1
    Registered User
    Join Date
    06-01-2012
    Location
    Nova Scotia, Canada
    MS-Off Ver
    Excel 2007
    Posts
    21

    Taking an integer out of a string

    Hi guys,

    I'm having some trouble taking a second string out of a dropbox I have. I'm able to get the first integer but am not able to get the second.

    In my drop box I have something like "Deck -- 32 -- 90" - Indicating the temperature in both C and F.

    I currently have:
    Please Login or Register  to view this content.
    This code extracts the 32, but I can't seem to manipulate it to get the 90 out! Any help would be greatly appreciated!

  2. #2
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Taking an integer out of a string

    Hi Mike,

    An easier might be text to columns.

    Used Fixed width >> Create columns around the numbers >> One the 3rd step of the wizard select the number numbers columns one by one and select Do not import column (skip)
    HTH
    Regards, Jeff

  3. #3
    Registered User
    Join Date
    06-01-2012
    Location
    Nova Scotia, Canada
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Taking an integer out of a string

    Quote Originally Posted by jeffreybrown View Post
    Hi Mike,

    An easier might be text to columns.

    Used Fixed width >> Create columns around the numbers >> One the 3rd step of the wizard select the number numbers columns one by one and select Do not import column (skip)

    If I understand what you're saying correctly, I'm not sure that'll work because I created a new column that combines multiple cells into one to display a large string for my drop down boxes in order to see all the data associated with that option. I may be misunderstanding your directions (I'm not by my computer thissecond) so I can test it in an hour or so)

  4. #4
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Taking an integer out of a string

    Next question, when you extract the 32 and 90, are they going in the same cell, two different cells...?

  5. #5
    Registered User
    Join Date
    06-01-2012
    Location
    Nova Scotia, Canada
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Taking an integer out of a string

    Quote Originally Posted by jeffreybrown View Post
    Next question, when you extract the 32 and 90, are they going in the same cell, two different cells...?
    2 different cells.. That code I copied is from a cell that requires that first 32. (works correctly)

  6. #6
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Taking an integer out of a string

    Hi Mike,

    To pull the 90...

    Try

    =--TRIM(RIGHT(SUBSTITUTE(Q24," ",REPT(" ",100)),100))

    BTW: This works for me to pull the 32...

    =LEFT(REPLACE(Q24,1,MIN(FIND({0,1,2,3,4,5,6,7,8,9},Q24&"0123456789"))-1,""),FIND(" ",Q24)-3)
    Last edited by jeffreybrown; 06-01-2012 at 01:49 PM.

  7. #7
    Registered User
    Join Date
    06-01-2012
    Location
    Nova Scotia, Canada
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Taking an integer out of a string

    Quote Originally Posted by jeffreybrown View Post
    Hi Mike,

    To pull the 90...

    Try

    =--TRIM(RIGHT(SUBSTITUTE(Q24," ",REPT(" ",100)),100))

    BTW: This works for me to pull the 32...

    =LEFT(REPLACE(Q24,1,MIN(FIND({0,1,2,3,4,5,6,7,8,9},Q24&"0123456789"))-1,""),FIND(" ",Q24)-3)


    The
    Please Login or Register  to view this content.
    doesn't seem to be working for me. It's giving me a blank cell.

  8. #8
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Taking an integer out of a string

    What does the string look like you are using this on?

    Deck -- 32 -- 90

    or

    "Deck -- 32 -- 90"

    If it's the latter, can you do a find and replace, remove the "" and then try again.

  9. #9
    Registered User
    Join Date
    06-01-2012
    Location
    Nova Scotia, Canada
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Taking an integer out of a string

    Quote Originally Posted by jeffreybrown View Post
    What does the string look like you are using this on?

    Deck -- 32 -- 90

    or

    "Deck -- 32 -- 90"
    Technically it looks like:

    Deck -- 32 -- 90(space)

    I would just use Right or some other function like that, but there are longer names and sometimes decimal places (doubles) so using right wouldn't be very effective and could cause some more problems.

  10. #10
    Valued Forum Contributor
    Join Date
    03-25-2004
    Location
    Boston, MA US
    Posts
    1,094

    Re: Taking an integer out of a string

    Hi Mike,

    If the last two characters are always the temperature then try:

    =RIGHT(Q24,2)*1

    If the first temperature (32) is always 2 characters try:

    =TRIM(MID(Q24,FIND(" ",Q24,1)+2,3))*1

    These both worked for me (also assuming the "--" are actually blanks if not replace the " " with "--").

    HTH
    Steve

  11. #11
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Taking an integer out of a string

    Try this modification of Jeff's formula

    =--TRIM(RIGHT(SUBSTITUTE(TRIM(Q24)," ",REPT(" ",100)),100))
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  12. #12
    Registered User
    Join Date
    06-01-2012
    Location
    Nova Scotia, Canada
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Taking an integer out of a string

    Quote Originally Posted by ChemistB View Post
    Try this modification of Jeff's formula

    =--TRIM(RIGHT(SUBSTITUTE(TRIM(Q24)," ",REPT(" ",100)),100))
    That worked perfectly.

    Thank you Jeff, SteveG, and ChemistB.. I appreciate all of your help!

  13. #13
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Taking an integer out of a string

    We're happy to help. Glad you have something to work with and thanks for the feedback

  14. #14
    Valued Forum Contributor
    Join Date
    03-25-2004
    Location
    Boston, MA US
    Posts
    1,094

    Re: Taking an integer out of a string

    Hi,

    This might not be the most elegant way but it worked for me using varying decmial points.

    for 32 - =MID(Q24,FIND(" -- ",Q24,1)+4,FIND(" -- ",Q24,FIND(" -- ",Q24,1)+4)-(FIND(" -- ",Q24,1)+4))*1
    for 90 - =MID(Q24,FIND(" -- ",Q24,FIND(" -- ",Q24,1)+4)+4,LEN(Q24)-FIND(" -- ",Q24,FIND(" -- ",Q24,1)+4)+4)*1

    HTH
    Steve

+ 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