+ Reply to Thread
Results 1 to 8 of 8

Select Case String

  1. #1
    Forum Contributor
    Join Date
    04-12-2012
    Location
    MD, England
    MS-Off Ver
    Excel 2003
    Posts
    142

    Select Case String

    Hi

    I am trying to send a string to a Select Case as in...

    Please Login or Register  to view this content.
    This will work but what I want to do is compose 'sFruit' elsewhere in the code

    Please Login or Register  to view this content.
    I've tried a number of variations like

    sFruit = """Apples"", ""Bananas""", ""Pears""" but it doesn't work.

    How can I do this?

    T.I.A.

  2. #2
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: Select Case String

    Haven't test it out yet, but maybe make your list into an array

    Please Login or Register  to view this content.

  3. #3
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Select Case String

    If you are trying to determine if a fruit is in a string of fruits, try:

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    04-12-2012
    Location
    MD, England
    MS-Off Ver
    Excel 2003
    Posts
    142

    Re: Select Case String

    Hi

    Please Login or Register  to view this content.
    Works almost, however another issue has arisen by coincidence. I am searching a closed wb's fieldnames using ADODB and just want to pull required fieldnames. What happened in testing is I came across sFruit = "Red plums. " i.e. with a dot.
    When the db is searched the fieldname in the db is interpreted as "Red plums# ". It is the # which is the issue now.
    Therefore when substituting real strings the code becomes...
    Instr("Apples, Red plums. , Pears", "Red plums# ") and that cannot match.
    I have tried wildcards without effect.

    For what it is worth the code looks like this...

    The search criteria is built from one opened wb by selecting anything up to 11 fieldnames using a form. Once done a number of selected but unopened wbs are searched for similar fields.
    It is better to do the search within the closed wb rather than import all the fields to the xla then search because of the varied construction of the closed wbs.

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    04-12-2012
    Location
    MD, England
    MS-Off Ver
    Excel 2003
    Posts
    142

    Re: Select Case String

    Hi JieJenn

    How would you iterate through the array?

    But apart from that another issue has arisen - see above to StephenM for an explanation please.
    Last edited by gmk; 04-29-2012 at 08:20 PM.

  6. #6
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Select Case String

    Therefore when substituting real strings the code becomes...
    Instr("Apples, Red plums. , Pears", "Red plums# ") and that cannot match.
    I have tried wildcards without effect.
    One way of handling this would be:

    Please Login or Register  to view this content.

  7. #7
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Select Case String

    For your information ... I've written two types of "IsFruit" functions.

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    04-12-2012
    Location
    MD, England
    MS-Off Ver
    Excel 2003
    Posts
    142

    Re: Select Case String

    By using "." rather than "" and then returning the fieldname in the same manner worked for me. Thank you.
    What I have to do now is research whether it is just dots that are changed into hashes in a db. If not I could still be looking for a solution using Replace.

    Please Login or Register  to view this content.

+ 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