3

I want to filter a column with particular value.

Problem Statement:
Excel looks like below and the worksheet name is "Current_Data".
enter image description here

I need to filter the third column with value "VP" and get the output using Autofilter.

Code snippet:

Sub Filter_CP()
Sheets("Current_Data").Range("A1:D4000").AutoFilter Field:=3, Criteria1:="VP"
End Sub

I receive the below error:

"Run-time error 1004: AutoFilter method of range class failed"

Instead of "Sheets", I tried with "Worksheets", without any luck.

Community
  • 1
  • 1
Niladri
  • 29
  • 4

1 Answers1

1

Other users have suggested code that works, assuming that your data is formatted correctly.

Verify that:

  • The left-most column of your range is A
  • The right-most column of your range is D
  • The first row of your range is 1

Once you have verified these things, try the code suggested by Siddharth Rout once again Sheets("Current_Data").Range("A1:D4000").AutoFilter Field:=3, Criteria1:="VP"

Furthermore, a screenshot that shows more could be useful to us when trying to help. For example, we cannot see the column letters nor row numbers in your image.

Finally, I would have commented this if I had enough reputation to do so, so apologies for essentially proposing another user's suggestion as an answer.

TehDrunkSailor
  • 633
  • 4
  • 11