+ Reply to Thread
Results 1 to 7 of 7

AutoFilter doesn't always return value set as default

  1. #1
    Registered User
    Join Date
    08-15-2013
    Location
    Cleveland, OH
    MS-Off Ver
    Excel 2010
    Posts
    4

    AutoFilter doesn't always return value set as default

    I am very new to VBA code and I have written the following to filter by the selected criteria, copy/paste into another sheet, or if the selection is not found then to clear contents and stop. I wanted to have the top value in the listbox selected by default, however, the autofilter doesn't always find the default value to return even though it is the same for all listboxes.

    Please Login or Register  to view this content.
    The criteria in field 2 is selected from listboxes with the following code:
    Please Login or Register  to view this content.
    I have been unable to figure out why this is happening, any ideas?

  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: AutoFilter doesn't always return value set as default

    Attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are demonstrated, mock them up manually if needed. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    08-15-2013
    Location
    Cleveland, OH
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: AutoFilter doesn't always return value set as default

    Filtering VBA.xlsm

    I have attached the file. When running the program you can see that the Criteria1:=L1S1FROM.Value for the different listboxes does not find the value and therefore can't return anything.

    Although if you manually click on the first item in the list which should have been selected by default then it always finds the value.

    Thanks for looking.

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

    Re: AutoFilter doesn't always return value set as default

    Does this work any better?
    Please Login or Register  to view this content.
    Note I deleted all the declarations for listboxes in the Initialize event as they aren't needed and could in fact cause confusion.

  5. #5
    Registered User
    Join Date
    08-15-2013
    Location
    Cleveland, OH
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: AutoFilter doesn't always return value set as default

    Norie,

    Thank you for your reply, that seems to have done the trick! Would you be able to explain why I was having that issue and how that solved it?

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

    Re: AutoFilter doesn't always return value set as default

    To be honest I couldn't figure out why that was happening so I tried another method of getting the values.

    The method I tried, using List and ListIndex, is what I would usually use.

    What might have been the problem was the declarations you had for the listboxes which, as I mentioned, aren't needed.

    Might be worth trying the original code without those declarations to see if that makes a difference.

  7. #7
    Registered User
    Join Date
    08-15-2013
    Location
    Cleveland, OH
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: AutoFilter doesn't always return value set as default

    Thanks Norie,

    I am now trying to create code that will allow me to pull up a listbox (for example: L1S1FROM), hold a selection from that box constant, and cycle through all of the values from another listbox (example: L1S1TO), each time hitting the execute button to generate a result. Any thoughts on how it might be best to do that?

    Thanks.

+ 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. Autofilter doesn't work in Excel VBA
    By facruz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-07-2009, 11:49 AM
  2. AutoFilter doesn't do work
    By asfaltboy in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-31-2009, 01:27 AM
  3. Book.xlt in doesn't open as default
    By Laura_lsmarketing in forum Excel General
    Replies: 9
    Last Post: 07-03-2006, 05:00 PM
  4. Autofilter doesn't work
    By tombogman in forum Excel General
    Replies: 7
    Last Post: 01-17-2006, 08:15 PM

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