• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA Macro to change autofilter based on cell value not working.

Riley

New Member
Hello,

I am using the following macro to change the autofilter of my data based on a cell value:

Sheets("Summary").Select

ActiveSheet.Range("$A$3:$DT$500").AutoFilter Field:=4, Criteria1:=portsel

For some reason it is "unchecking" the Criteria1 from the filter dropdown list instead of deselecting all the other options.

Please help.

Thanks,
R
 
I don't know what you exactly want. You can try this.

Code:
Sheets("Summary").Select

ActiveSheet.Range("$A$3:$DT$3").AutoFilter Field:=4, Criteria1:="portsel"

For more clarification, upload relative file.
 
Hi,

Apologies for the confusion. In the attached file, I want to select a port in cell "C2", Sheet "Port Select" and click the "update button" to run the macro, which should filter the data on the "data" tab by the port selected.

Thanks,
 

Attachments

  • SampleFilterData.xlsm
    16.2 KB · Views: 2
Hi ,

If the blanks are in column B , no modification is required ; any selection , whether it is East , West , North or South , will include only those rows where column B has the selected text ; thus those rows which are blank in column B are automatically excluded.

If you want that blanks in other columns are excluded , then see the attached file.

Narayan
 

Attachments

  • SampleFilterData.xlsm
    16.5 KB · Views: 3
Hi Narayan,

Thanks for the quick response. For some reason when I use the original code it returns the following (see attached photo) instead of the desired port.

Regards,
 
Hi Narayan,

I think I was able to figure out the cause of the problem. Thank you all for the help along the way!

Regards,
 
Hi,

I have decided to add some complexity to my example and it is not working as planned. I added filter macros for boat and cargo in the attached example. Unfortunately, when I leave "cargoselect" blank it returns me zero results in my data tab as demonstrated.

Any suggestions?

Thanks,
 

Attachments

  • SampleFilterData.xlsm
    17 KB · Views: 0
Back
Top