Auto Filter From Sh1 / Sh2

Edgarvelez

Board Regular
Joined
Jun 6, 2019
Messages
197
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

Cant quite figure this one out how to write the last line, I ma not writing it correctly.
I am filtering in sh2 based on sh1.

VBA Code:
    Dim sh1 As Worksheet, sh2 As Worksheet
    Set sh1 = Sheets("DashBoard")
    Set sh2 = Sheets("Sheet1")
    Select Case sh1.Range("B3").Value
    Case "Sheet Line No."
    
   Dim Ary As Variant
With sh1.Range("A7", .Range("A" & Rows.Count).End(xlUp))
         Ary = .Worksheet.Evaluate("transpose(if({1}," & .Address & "&""""))")
      End With
   End With
      Sh2.("Sh1.Range("A2:G2").AutoFilter 1, Ary, xlFilterValues
End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Are you trying to filter sh2, based on the values in sh1 A7 downwards?
 
Upvote 0
Hi,
Actually it was your code originally you provided me below but I have changed it because I am using case.
VBA Code:
Sub Edgarvelez()
   Dim Ary As Variant
   
   With Sheets("DashBoard")
      With .Range("I4", .Range("I" & Rows.Count).End(xlUp))
         Ary = .Worksheet.Evaluate("transpose(if({1}," & .Address & "&""""))")
      End With
   End With
   Sheets("Sheet1").Range("A2:G2").AutoFilter 1, Ary, xlFilterValues
End Sub
 
Upvote 0
Can you please explain exactly what you want to do?
 
Upvote 0
Trying to filter sh2, based on the values in sh1 A7 downwards using the format below sh1 = Sheets("DashBoard") and sh2 = Sheets("Sheet1")

VBA Code:
    Dim sh1 As Worksheet, sh2 As Worksheet
    Set sh1 = Sheets("DashBoard")
    Set sh2 = Sheets("Sheet1")
    
    
    Select Case sh1.Range("B3").Value
    Case "Sheet Line No."
    
   Dim Ary As Variant
With sh1.Range("A7", .Range("A" & Rows.Count).End(xlUp))
         Ary = .Worksheet.Evaluate("transpose(if({1}," & .Address & "&""""))")
      End With
   End With
      Sh2.(Sh1.Range("A2:G2").AutoFilter 1, Ary, xlFilterValues
End Sub
 
Upvote 0
But what about the select case, what is that for?
 
Upvote 0
Because I will have 2 variants of the code depending on what I select in B3 of sh1.
The first variant of the code will be:
("A2:G2").AutoFilter 1, Ary, xlFilterValues
The second Variant of the code will be
("C2:G2").AutoFilter 1, Ary, xlFilterValues
once you help me with the first I can do the second and not bother too much.
 
Upvote 0
Ok, how about
VBA Code:
   Dim Ary As Variant
   Set sh1 = Sheets("DashBoard")
   Set sh2 = Sheets("Sheet1")
   
   Select Case sh1.Range("B3").Value
      Case "Sheet Line No."
      
      With sh1.Range("A7", sh1.Range("A" & rows.count).End(xlUp))
         Ary = .Worksheet.Evaluate("transpose(if({1}," & .Address & "&""""))")
      End With
      sh2.Range("A2:G2").AutoFilter 1, Ary, xlFilterValues
   End Select
 
Upvote 0
Solution
Awesome it worked thank you so much.
This it what the full code looks like:
VBA Code:
   Set sh1 = Sheets("DashBoard")
   Set sh2 = Sheets("Sheet1")
   
   
   Dim Ary As Variant
   Select Case sh1.Range("B3").Value
      Case "Sheet Line No."
      With sh1.Range("A7", sh1.Range("A" & Rows.Count).End(xlUp))
         Ary = .Worksheet.Evaluate("transpose(if({1}," & .Address & "&""""))")
      End With
      sh2.Range("A2:G2").AutoFilter 1, Ary, xlFilterValues
      
      Case "Batch No."
      With sh1.Range("A7", sh1.Range("A" & Rows.Count).End(xlUp))
         Ary = .Worksheet.Evaluate("transpose(if({1}," & .Address & "&""""))")
      End With
      sh2.Range("C2:G2").AutoFilter 1, Ary, xlFilterValues
      
   End Select
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top