Dynamic CriteriaRange for Dynamic Filtering Macro

Garmerr

New Member
Joined
Sep 13, 2017
Messages
10
Office Version
  1. 365
Platform
  1. Windows
Hello All,
I am trying to enhance a macro to allow for a dynamic criteria range that will be used for creating a dynamic filter. In the code below, the CriteriaRange is currently defined as:

CriteriaRange:=Range("Q3:Q11")

What I want is for the list to Q3:Q#, where number represents the last row with data in this column. This list will change in the number of rows populated, but will always start at Q3.

Code:
Sub ItemList()'
' ItemList Macro
' Copy Unique Item List
'


'
    Application.CutCopyMode = False
    Application.CutCopyMode = False
    Application.CutCopyMode = False
    Range("Table1[[#All],[Supplier]:[Description]]").AdvancedFilter Action:= _
        xlFilterCopy, [B]CriteriaRange:=Range("Q3:Q11")[/B], CopyToRange:=Range("W2"), _
        Unique:=True
Dim sht As Worksheet
Dim LastRow As Long
Dim LastColumn As Long
Dim StartCell As Range


Set sht = Worksheets("Current Quarter FC")
Set StartCell = Range("W3")


'Find Last Row and Column
  LastRow = sht.Cells(sht.Rows.Count, StartCell.Column).End(xlUp).Row
  LastColumn = sht.Cells(StartCell.Row, sht.Columns.Count).End(xlToLeft).Column


'Select Range
  sht.Range(StartCell, sht.Cells(LastRow, LastColumn)).Select
    Selection.Copy
    Sheets("SC Item Review").Select
    Range("A2").Select
    ActiveSheet.Paste
    Columns("A:D").Select
    Selection.Columns.AutoFit
    Range("A2").Select
Dim LastR As Long


'FIND LAST ROW OF DATA IN COLUMN 1 (A)
LastR = Cells(Rows.Count, 1).End(xlUp).Row


'COPY FROM ROW 2 OF COL 5 (E) TO LAST ROW OF COLUMN A IN COLUMN 8 (H)
Range(Cells(2, 5), Cells(LastR, 10)).FillDown
    Range("H2").Select
End Sub

Thanks for your time.
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
How about
Code:
[B]Range("Q3",range("Q"&Rows.Count).end(xlup))[/B]
 
Upvote 0
Solution
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,583
Members
449,089
Latest member
Motoracer88

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