+ Reply to Thread
Results 1 to 7 of 7

Convert complex text format to TEXT STRING?

  1. #1
    Registered User
    Join Date
    04-02-2021
    Location
    NYC USA
    MS-Off Ver
    18.2008.12711.0
    Posts
    3

    Convert complex text format to TEXT STRING?

    I have a sheet that is a kind of inventory, where there are many categories of item. Each line of the inventory has a different embedded Custom Format in the form:

    "("0") Type of Item, in Color X"

    So when you type a number in that cell, say 5, it displays:

    (5) Type of Item, in Color X

    But it is a number, not a text string, so you can multiply it or add them or whatever you need to do. If you make another cell = to that cell, you get the numerical value, as it should be.

    My question is this - is there a way to take any cell with a complex format involving characters like this, copy it, and paste it as a TEXT STRING? Or use a function or a VBA routine to capture the whole thing as a text string?

    Using my example above that would mean being able to create a text string in another cell that reads "(5) Type of Item, in Color X"

    I realize you will be tempted to offer suggestions about another way to organize the spreadsheet. I understand that.
    But, please, I really do want to know the answer to this question of essentially converting formatted numbers to text strings for general knowledge and future reference.

    Thanks!

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,422

    Re: Convert complex text format to TEXT STRING?

    Maybe:
    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,422

    Re: Convert complex text format to TEXT STRING?

    As a Function

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    04-02-2021
    Location
    NYC USA
    MS-Off Ver
    18.2008.12711.0
    Posts
    3

    Re: Convert complex text format to TEXT STRING?

    Hmmm. Thanks. I'll give it a try.

  5. #5
    Registered User
    Join Date
    04-02-2021
    Location
    NYC USA
    MS-Off Ver
    18.2008.12711.0
    Posts
    3

    Re: Convert complex text format to TEXT STRING?

    Brilliant. Works.
    Thanks.

  6. #6
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: Convert complex text format to TEXT STRING?

    This would be a custom number format. There's no worksheet function which returns a cell's full number format. CELL("format") is stuck mimicking the functionality of Lotus 1-2-3 Release 2.x from the mid-1980s, so it's not useful for this. You could use the XLM function GET.CELL in defined names, but that's inflexible.

    Which leaves VBA as the best means for accessing a cell's .Text property. Note: changing number formats does NOT trigger recalculation at all, so even making user-defined functions (UDFs) volatile won't make formulas recalculate when number formats change. Meaning if you want to use such UDFs, you're going to need to develop the habit of pressing [F9] early & often.

    Anyway, as a UDF,

    Please Login or Register  to view this content.
    The formula =gettext(X99) should return exactly what's displayed in cell X99 except for colors and font effects like boldface, italics, font size.

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,422

    Re: Convert complex text format to TEXT STRING?

    You're welcome.

+ 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: 6
    Last Post: 10-13-2017, 03:32 PM
  2. Storing complex text string into variable. Text string contains html or xml code.
    By jakopak in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-20-2015, 04:54 AM
  3. Replies: 1
    Last Post: 04-24-2014, 12:25 AM
  4. Macro to save text string as an MS-DOS format text document
    By bwink88 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-16-2013, 02:25 PM
  5. [SOLVED] Use VBA to run "text to columns' Loop on first row to convert from text to date format
    By csmiley in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-03-2013, 02:06 PM
  6. [SOLVED] Macro to convert specific text and format specific text within a string
    By Mencae in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 12-06-2012, 12:13 AM
  7. How do I convert a text string to a time format
    By knighttrader in forum Excel General
    Replies: 8
    Last Post: 01-29-2008, 04:19 AM

Tags for this Thread

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