VBA Code To Filter A Column By A Cell Reference

By Gaurav Chhokar
Updated on Oct 12, 2019



How to filter a column by a value which is in specific cell. If you change the value of that cell filter will change according. 

Sub Filter_by cellvalue()

Dim ws2 As Worksheet
Dim ws1 As Worksheet
Set ws2 = ThisWorkbook.Sheets("Sheet2")
Set ws1 = ThisWorkbook.Sheets("Sheet1")

With ws1.Range("A:Z")


'I filter the date by cell B2 which is in sheet 2 and column 7 which is filtered is in sheet 1 
. AutoFilter Field:=7, Criteria1:=">=" & ws2.Range("B2"), Operator:=xlAnd


'filter by any string like i used MPL Which is available in the column 3 
.AutoFilter Field:=3, Criteria1:="MPL", Operator:=xlAnd

End With


End Sub
VBA Code To Filter A Column By A Cell ReferenceVBA Code To Filter A Column By A Cell Reference Reviewed by Gaurav Chhokar on October 12, 2019 Rating: 5

No comments:

Powered by Blogger.