+ Reply to Thread
Results 1 to 10 of 10

Select Case statements after Search String not working

  1. #1
    Registered User
    Join Date
    10-31-2013
    Location
    Golden, CO
    MS-Off Ver
    Excel 2010
    Posts
    43

    Select Case statements after Search String not working

    I am attempting to use a search string that will take priority over some select statements. The Search String statements run correctly, but the Select Statements get skipped over and dont populate.

    Please Login or Register  to view this content.
    Thanks,
    Ray

  2. #2
    Forum Contributor
    Join Date
    11-15-2012
    Location
    Buffalo, NY
    MS-Off Ver
    Office 365
    Posts
    286

    Re: Select Case statements after Search String not working

    Negative logic sucks, doesn't it.

    Your code says:

    Please Login or Register  to view this content.
    Well, if a cell DOES contain one of those somethings, then it most certainly does NOT contain any of the other somethings, so the only thing that will cause your nifty piece of code to execute will be if the cells contain NONE of the suggested strings. I don't think that's what you wanted.

    Please Login or Register  to view this content.
    may be a better and easier to read way of expressing your intent!

    HTH

    Tony

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Select Case statements after Search String not working

    Assuming that the search lines work. Try to use one of the lines for the select case range

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    10-31-2013
    Location
    Golden, CO
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: Select Case statements after Search String not working

    thanks, his code update appears to work but has highlighted the fact that my search lines do not work correctly. Any suggestions of having the search string look for cells that contain the identified values within the text and return the entire cell contents if a match occurs?


    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    11-15-2012
    Location
    Buffalo, NY
    MS-Off Ver
    Office 365
    Posts
    286

    Re: Select Case statements after Search String not working

    Please Login or Register  to view this content.
    If Anyone of those conditions is true, then you want to do the Select statement, right?

    Consider the case where Instr(1,pCell.Value,"TSC") is > 0.

    Both of the other two conditions will return FALSE, and as a result the entire condition (joined by AND operators) will also return FALSE.

    That's what I meant when I said that negative logic sucks!

    Instr will return 0 or above, so the whole <>0 is unnecessary - it sucks you into the negative logic thingy. Test for what you want (or at least for what you can get easily), and then use an ELSE clause if necessary.

    HTH

    Tony

  6. #6
    Registered User
    Join Date
    10-31-2013
    Location
    Golden, CO
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: Select Case statements after Search String not working

    Thank you for you assistance, but this is not what I'm attempting to do. What I'm hoping to accomplish is to have the InStr statements handle exceptions to the Select statements. So in the case of Instr(1,pCell.Value,"TSC") is > 0, if the contents of the pCell does contain the string "TSC", such as '83TSC91780', then I need the code to return the entire contents of pCell. Otherwise if the contents of pCell did not contain the "TSC" string, I need the code to perform the Select Statements. In a different example, if the contents of pCell did not contain the string "TSC", such as ('97UNKN9170'), then I would need the Case Is = 10 Range("D" & pCell.Row).FormulaR1C1 = "= LEFT(RC[-1],7)" Select statement to be performed. Hope this is clearer than mud.

    Thanks again!

    Ray

  7. #7
    Forum Contributor
    Join Date
    11-15-2012
    Location
    Buffalo, NY
    MS-Off Ver
    Office 365
    Posts
    286

    Re: Select Case statements after Search String not working

    Sort of like this?
    Please Login or Register  to view this content.
    I think the issue all along has been When to do something, much more than What to do!

    I hope that waters are less turbid, now!

    Tony

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Select Case statements after Search String not working

    Maybe ...

    Please Login or Register  to view this content.
    Last edited by shg; 12-10-2013 at 03:55 PM.
    Entia non sunt multiplicanda sine necessitate

  9. #9
    Registered User
    Join Date
    10-31-2013
    Location
    Golden, CO
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: Select Case statements after Search String not working

    shg, that appears to work great. Ill do some more testing here in a bit to verify, but thank you!

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Select Case statements after Search String not working

    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. Password and case statements codes not working, but not erroring either
    By pjbassdc in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-09-2013, 09:32 AM
  2. Multiple IF statements, or a select case?
    By rob2k77 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-22-2013, 03:31 PM
  3. help with if then select case statements
    By timermel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-26-2011, 05:35 PM
  4. Can arrays be identified by i = X TO Y statements? (Avoid select Case)
    By macyarab in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-18-2009, 08:21 AM
  5. Select Case Statements
    By ladeda063610 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-06-2008, 11:25 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