Dynamic Macro to copy rows based on selected criteria

Mavericks334

Active Member
Joined
Jan 26, 2011
Messages
280
Hi

Below is my macro to copy rows based on selected criteria. The Row number would be changing every month.

Sheets("Active Vendors").Select
Range("A1").Select
Selection.AutoFilter
Range("AD1").AutoFilter Field:=34, Criteria1:=Array( _
"KPMG Advisory SRL", "Magna Infotech Pvt Ltd", "PRICEWATERHOUSE COOPERS LLP", _
"S R Batliboi"), Operator:=xlFilterValues
ActiveSheet.Range("$A$1:$AP$26").AutoFilter Field:=34, Criteria1:=Array( _
"KPMG Advisory SRL", "Magna Infotech Pvt Ltd", "S R Batliboi"), Operator:= _
xlFilterValues
Range("AF5:AL5").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy

The row may not always start at A5, could be at a2 or even a6.

How do i make my macro dynamic.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Try this. It will copy only the visible filtered rows even though it starts at row 2.

Code:
    [color=darkblue]With[/color] Sheets("Active Vendors")
        
        .Range("A1").AutoFilter
                    
        .Range("A1:AP26").AutoFilter Field:=34, Criteria1:=Array( _
              "KPMG Advisory SRL", "Magna Infotech Pvt Ltd", _
              "S R Batliboi"), Operator:=xlFilterValues
              
        [color=green]'Copy visible rows from AF:AP[/color]
        .Range("AF2", .Range("AF" & Rows.Count).End(xlUp)).Resize(, 7).Copy
        
    [color=darkblue]End[/color] [color=darkblue]With[/color]
 
Upvote 0
The PRoblem is i dont wish it copies only from AF2. It needs to copy from A2. and the rows will not be limited to 26. could even be more or less.
 
Upvote 0
Windows(Fname).Activate
Sheets("Active Temp Agency_2").Select
Selection.AutoFilter
Range("AD1").AutoFilter Field:=30, Criteria1:= _
"Investment Management Services"
Range("A1:AL1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Windows("FTS_HC.xls").Activate
Sheets("Active Temp Agency").Select
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Active Vendors").Select
Range("A1").Select
Selection.AutoFilter
Range("AD1").AutoFilter Field:=34, Criteria1:=Array( _
"KPMG Advisory SRL", "Magna Infotech Pvt Ltd", _
"S R Batliboi"), Operator:=xlFilterValues
Rows("2:2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("Active Temp Agency").Select
Selection.End(xlDown).Select
 
Upvote 0

Forum statistics

Threads
1,214,592
Messages
6,120,433
Members
448,961
Latest member
nzskater

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