Results 1 to 4 of 4

Thread: Convert numbers to a specific text string

  1. #1

    Convert numbers to a specific text string



    Register for a FREE account, and/
    or Log in to avoid these ads!

    Hello,

    I have a number that I need to convert to the following text string formats. I have successfully converted 45 to the following text string using the custom format:
    Wait(45000);

    But it does not work with the ones below:

    Convert 0.05 to the following text string:
    <ParameterString>0.05</ParameterString>

    Convert 0 to the following text string:
    <Time>0</Time>

    These are codes for a instrument and the text must be in the exact format above. Can anyone help.

    Regards,

    Frank

  2. #2
    Administrator Ken Puls's Avatar
    Join Date
    Mar 2011
    Location
    Nanaimo, BC, Canada
    Posts
    2,294
    Articles
    57
    Blog Entries
    14
    Excel Version
    Excel Office 365 Insider
    Hi Frank, and welcome to the forum.

    You stumbled on something that surprises me with "Wait". I can't find much other text that works in the text function.

    At any rate, easy to do with Substitute. The <> characters work, so we can Substitute ParameterString> in for >, and the { character also works. We can then Substitute in the / for that as follows:

    =SUBSTITUTE(SUBSTITUTE(TEXT(B6,"<>#.##<{>"),">","ParameterString>"),"{","/")

    Likewise, for Time:

    =SUBSTITUTE(SUBSTITUTE(TEXT(B6,"<>#.##<{>"),">","Time>"),"{","/")

    Both assuem your data is in cell B6, so you'll need to correct that.

    Hope that helps,
    Ken Puls, FCPA, FCMA, MS MVP

    Learn to Master Your Data at the Power Query Academy (the world's most comprehensive online Power Query training), with my book M is for Data Monkey, or our new Power Query Recipe cards!

    Main Site: http://www.excelguru.ca -||- Blog: http://www.excelguru.ca/blog -||- Forums: http://www.excelguru.ca/forums
    Check out the Excelguru Facebook Fan Page -||- Follow Me on Twitter

    If you've been given VBA code (a macro) for your solution, but don't know where to put it, CLICK HERE.

  3. #3
    Hi Ken,
    Its been a while since I visited here, so I'll start with this easy one
    Nice use of SUBSTITUTE, but isn't it easier to use the TEXT function with format strings? Like,
    =TEXT(B6,"""<ParameterString>""#0.00""</ParameterString>""")
    =TEXT(B6,"""<Time>""#0""</Time>""")

  4. #4
    Administrator Ken Puls's Avatar
    Join Date
    Mar 2011
    Location
    Nanaimo, BC, Canada
    Posts
    2,294
    Articles
    57
    Blog Entries
    14
    Excel Version
    Excel Office 365 Insider
    Hi Ed,

    I have a habit of making things difficult sometimes.
    Ken Puls, FCPA, FCMA, MS MVP

    Learn to Master Your Data at the Power Query Academy (the world's most comprehensive online Power Query training), with my book M is for Data Monkey, or our new Power Query Recipe cards!

    Main Site: http://www.excelguru.ca -||- Blog: http://www.excelguru.ca/blog -||- Forums: http://www.excelguru.ca/forums
    Check out the Excelguru Facebook Fan Page -||- Follow Me on Twitter

    If you've been given VBA code (a macro) for your solution, but don't know where to put it, CLICK HERE.

Posting Permissions

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