menaafraim8
New Member
hello friends
Since i'm new to VBA coding i'm tring to write a code that filter data based on variable cells comes from another filter in the same sheet, but keep replyig with the first value only of the selected criteria, any suggestions?
Since i'm new to VBA coding i'm tring to write a code that filter data based on variable cells comes from another filter in the same sheet, but keep replyig with the first value only of the selected criteria, any suggestions?
Code:
Sub FilterCriteria()
Dim vCrit As Variant
Dim wsO As Worksheet
Dim wsL As Worksheet
Dim rngOrders As Range
Set wsO = Worksheets("Orders")
Set wsL = Worksheets("Lists")
Set rngOrders = wsO.Range("$A$1").CurrentRegion
rngOrders.AutoFilter _
Field:=6, Criteria1:=Array("51", "55", "71"), _
Operator:=xlFilterValues
Dim rngCrit As Range
Set rngCrit = wsO.Range("D2:D" & Range("D" & Rows.Count).End(xlUp).Row).SpecialCells(xlCellTypeVisible)
rngOrders.AutoFilter Field:=6 'To remove other filter to be able to look up in the whole sheet
vCrit = rngCrit.Value
rngOrders.AutoFilter _
Field:=4, _
Criteria1:=Application.Transpose(vCrit), _
Operator:=xlFilterValues
End Sub