• 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.

I need help for filtering the data in VBA.

ThrottleWorks

Excel Ninja
Hi,


I need help for filtering the data in VBA.

I need to filter the value as per month names.


I have given an input box where user puts the name of the month.

The user can select any month between Jan to Dec.

This values is stored in cell B1.


My problem is, I want to filter the data on the basis of value in cell B1.

For example if the user has selected December, the macro should filter the data for December.


Can anyone please help me here, I tried recording, but macro is recording the particular cell value as string & doesn’t get changed even if if we changed the value in B1.
 
Make your data into a table and use:


filter = "=" & Range("f1").Value

MsgBox filter


ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=1, Criteria1:= _

filter, Operator:=xlAnd
 
Hi Dan, Thanks a lot for the help.

However I am getting a bug while trying to run the code,


Can you please help me to locate my mistake.


----------------------------------------------------


Code entered


Sub test()


filter = "=" & Range("b1").Value

MsgBox filter


ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=1, Criteria1:= _

filter, Operator:=xlAnd


End Sub

--------------------------------------


my table is in sheet1 ("A1:I5").


I am getting error as, complile error, argument not optional.
 
This code assumes you've defined a table: excel 07/10, insert>table and the table is named Table 1.


ARe you using 07 or 10?
 
Back
Top