+ Reply to Thread
Results 1 to 3 of 3

Select Case possibly not working as intended. (Another strange bug)

  1. #1
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Select Case possibly not working as intended. (Another strange bug)

    I've made a test file to duplicate this issue. When you are looping through a variable to delete columns based on the header I can't get the select case statement to register the final column unless I add a useless variable. Let me show you what I mean.

    Please Login or Register  to view this content.
    The only difference between test and test2 is test2 has an extra variable on my "Select Case" statement. Now if you take a normal worksheet and label A1 = "red", B1 = "blue", and C1 = "green" then the Sub test will delete "red". If you run test2 the code will not delete "red".

    Maybe there is a solution for this and maybe not. I am more interested in the reasoning why test fails and test2 works. Does anyone know what is going on?
    Attached Files Attached Files

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Select Case possibly not working as intended. (Another strange bug)

    Your Select Case isn't right.

    It should probably be this as Header is Cells(1,x).
    Please Login or Register  to view this content.
    Oh, and you don't need the If Header = "" and the Goto.
    Last edited by Norie; 08-16-2013 at 10:30 AM.
    If posting code please use code tags, see here.

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Select Case possibly not working as intended. (Another strange bug)

    The actual test in your select are

    Please Login or Register  to view this content.
    The first condition in the select statement will evaluate to False which is valid but not met. I the second code set you have that test and all the available colours. So it works. In the first code set the test is

    Please Login or Register  to view this content.
    which evalutates to False except when x=1 then it evaluates to True. But at no time is "red" on it's own compared, which is why when red is tested the column is deleted.

    As Noire suggested alter your case conditions.
    Cheers
    Andy
    www.andypope.info

+ 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. [SOLVED] VLOOKUP not working as intended
    By RAS 2112 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-12-2013, 08:58 AM
  2. my Select Case function is not working correctly
    By DorothyFan1 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-25-2011, 07:56 AM
  3. [SOLVED] Case Select not working
    By Aland2929 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-14-2010, 06:53 AM
  4. Wont select the row intended
    By therealjag in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-23-2010, 11:38 AM
  5. Select Case not working
    By RadBrad in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-31-2009, 01:11 AM

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