VBA code to filter with a dynamic range, count and delete

SamCha

New Member
Joined
Nov 23, 2020
Messages
30
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

Having difficulty in understanding how to go about on this one. I am using the below vba code to filter Col. B in Sheet 2 based on the names in Col. L in Sheet 1 (the name range is dynamic). Sheet 2 will apply filter based on the values in Sheet 1 in Range L:L, count the number of visible rows, return the count in Sheet 1 in Range C6 and then delete the rows. I could only go not even half way through from the below code. It only filters by the first name written in column L. Please suggest.

VBA Code:
Sub Filterbyname()

Dim InputSt As Worksheet, 
Dim NameSt As Worksheet
Dim List As Variant
Dim InputLR As Long
 Set NameSt = Sheets("Sheet2")
 Set InputSt = Sheets("Sheet1")
 
 
 InputSt.Activate
    
    With InputSt
    
    InputLR = InputSt.Cells(InputSt.Rows.count, "L").End(xlUp).Row
    List = Range(Cells(1, 12), Cells(InputLR, 12)).Value
 
End With

NameSt.Activate

ActiveSheet.Range("B2").AutoFilter Field:=2, Criteria1:=List, Operator:=xlFilterValues

End Sub

Thanks in advance
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
How about
VBA Code:
NameSt.Range("B2").AutoFilter Field:=2, Criteria1:=Application.Transpose(List), Operator:=xlFilterValues
 
Upvote 0

Forum statistics

Threads
1,215,004
Messages
6,122,659
Members
449,091
Latest member
peppernaut

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