+ Reply to Thread
Results 1 to 7 of 7

Data Validation: Escaping Commas in Choice List

  1. #1
    Registered User
    Join Date
    12-18-2012
    Location
    Houston TX
    MS-Off Ver
    Excel 2007
    Posts
    19

    Data Validation: Escaping Commas in Choice List

    I'm building VBA code which installs Data Validation drop-down menues on certain cells across multiple worksheets. Each menu may be different; I build a comma-separated string of choices and install in in the cell with code which looks similar to
    Please Login or Register  to view this content.
    And this works just fine. HOWEVER, for one cell, the choices (as given to me by the user) are:
    • 3 In, 1 Out
    • 2 In, 2 Out
    • 1 In, 3 Out
    But if I spec
    Please Login or Register  to view this content.
    of course I get six choices, none of them containing commas. I've tried obvious things like
    Please Login or Register  to view this content.
    without any luck.

    I may yet resort to hacks like changing the commas to semicolons, or writing the choices into cells and spec'ing the choices by a range-pointer. But I thought I'd check here first: is there some way to escape the commas so that the Data Validation teams don't split on them?

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Data Validation: Escaping Commas in Choice List

    No, you cannot use commas as part of the text strings in a DV list. Use a hyphen, it looks as clean.

    •3 In - 1 Out
    •2 In - 2 Out
    •1 In - 3 Out
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Data Validation: Escaping Commas in Choice List

    BTW, you CAN have commas in a DV list that is a range source to a set of cells on a sheet somewhere. So if you absolutely must have commas for some reason unexplained, instead of creating a string with commas and inserting directly into the VB, collect the strings into a range of cells, then set the DV list to use that range of cells as the source. Then you get your commas.

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Data Validation: Escaping Commas in Choice List

    you could use chr(130) instead of the comma within the values. the user won't be able to type values in though-they'd have to use alt+0130 to enter the comma
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  5. #5
    Registered User
    Join Date
    12-18-2012
    Location
    Houston TX
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: Data Validation: Escaping Commas in Choice List

    Thanks for your feedback. Unfortunately, the commas have to be there and they really have to be commas - the choices are set in another standard, and it needs to match character-for-character. Other matters were forcing me towards building a separate worksheet and putting all the choices into ranges. Turns out there's a 255 char limit on the comma-delimited choice-list, so I have to go to ranges anyways. But thanks for the clarifications.

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Data Validation: Escaping Commas in Choice List

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.
    Thanks.

  7. #7
    Registered User
    Join Date
    07-02-2012
    Location
    Nairobi,Kenya
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: Data Validation: Escaping Commas in Choice List

    Formula1:="3 In" & Chr(130) & " 1 Out,2 In" & Chr(130) & "2 Out,1 In" & Chr(130) & " 3 Out"
    This should cover you

+ 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