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

SamCha

New Member
Joined
Nov 23, 2020
Messages
28
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
 

Some videos you may like

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,229
Office Version
  1. 365
Platform
  1. Windows
How about
VBA Code:
NameSt.Range("B2").AutoFilter Field:=2, Criteria1:=Application.Transpose(List), Operator:=xlFilterValues
 

Watch MrExcel Video

Forum statistics

Threads
1,126,911
Messages
5,621,595
Members
415,847
Latest member
AlpinoHirsch

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
Top