0

I have two sheets in a workbook. I am using the following VBA code to filter the data:

Sub apply_autofilter_across_worksheets()
'Updateby Extendoffice 20160623
    Dim xWs As Worksheet
    On Error Resume Next
    For Each xWs In Worksheets
        xWs.Range("A4").AutoFilter 1, "=001"
    Next
End Sub

Now I want to use the value in cell F1 in place of 001. How do I modify the code?

0

That's pretty easy mate, try:

Sub apply_autofilter_across_worksheets()

    ' Updateby Extendoffice 20160623

    Dim xWs As Worksheet
    On Error Resume Next
    For Each xWs In Worksheets
        xWs.Range("A4").AutoFilter FIELD:=1, CRITERIA1:=xWs.range("F1").value
    Next
End Sub

cheers

  • Thank you. But I have many worksheet in same workbook and I want to change at a time. Can you help me out. – Suyash Nov 27 '18 at 3:52
  • @Suyash You want to pick a sheet in specific? Because you are looping all the sheets on this workbook. – dmb Nov 27 '18 at 3:58
  • It is not working with other sheet Can you help me. – Suyash Nov 28 '18 at 7:41

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.