Filtered Rows

pwill

Active Member
Joined
Nov 22, 2015
Messages
406
Hi can anyone help with the following macro?

I am filtering Data on Sheet1 "A:Z" with headers on row 1 and then copying the visible filtered rows to the next empty rows on sheet2
"A:Z"

This macro works but I don't want to use copy and paste and wondered if it is possible to change the lines in red to something else? where sheet2 could just equal the filtered rows from sheet1 to the next empty rows.

ie I have tried re-arranging the copy and paste lines to -

'target.Range("A" & lRow & ":Z" & lRow) = copyRng.SpecialCells(xlCellTypeVisible).Value'

Here is the code I have, any help would be much appreciated

Code:
[FONT=Verdana]Sub Filter()
[/FONT]
[FONT=Verdana]Dim source As Worksheet
Dim target As Worksheet
Dim filtrRng As Range
Dim copyRng As Range
Dim lRow As Long
[/FONT]
[FONT=Verdana]    Set source = Sheet1
    Set target = Sheet2
    
    source.AutoFilterMode = False
[/FONT]
[FONT=Verdana]    lRow = source.Cells(Rows.Count, "A").End(xlUp).Row
    
    Set filtrRng = source.Range("A1:Z" & lRow)
    Set copyRng = source.Range("A2:Z" & lRow)
    
    filtrRng.AutoFilter field:=2, Criteria1:="3"
    
    [COLOR=#ff0000]copyRng.SpecialCells(xlCellTypeVisible).Copy[/COLOR]
    
    lRow = target.Range("A" & Rows.Count).End(xlUp).Row + 1
    
   [COLOR=#ff0000] target.Range("A" & lRow & ":Z" & lRow).PasteSpecial xlPasteValues[/COLOR]
    
    [COLOR=#008000]'target.Range("A" & lRow & ":Z" & lRow) = copyRng.SpecialCells(xlCellTypeVisible).Value[/COLOR]
[/FONT]
[FONT=Verdana]End Sub[/FONT]

regards

pwill
 
Last edited:

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Data on Sheet1

[TABLE="width: 695"]
<tbody>[TR]
[TD="align: center"]
[/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]D[/TD]
[TD="align: center"]E[/TD]
[TD="align: center"]F[/TD]
[TD="align: center"]G[/TD]
[TD="align: center"]H[/TD]
[TD="align: center"]I[/TD]
[TD="align: center"]J[/TD]
[TD="align: center"]K[/TD]
[TD="align: center"]L[/TD]
[TD="align: center"]M[/TD]
[TD="align: center"]N[/TD]
[TD="align: center"]O[/TD]
[TD="align: center"]P[/TD]
[TD="align: center"]Q[/TD]
[TD="align: center"]R[/TD]
[TD="align: center"]S[/TD]
[TD="align: center"]T[/TD]
[TD="align: center"]U[/TD]
[TD="align: center"]V[/TD]
[TD="align: center"]W[/TD]
[TD="align: center"]X[/TD]
[TD="align: center"]Y[/TD]
[TD="align: center"]Z[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]Ref[/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]Ref[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]Ref[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]Ref[/TD]
[TD="align: center"]D[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD="align: center"]13643[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]-3[/TD]
[TD="align: center"]9[/TD]
[TD="align: center"]-12[/TD]
[TD="align: center"]-17[/TD]
[TD="align: center"]18[/TD]
[TD="align: center"]20[/TD]
[TD="align: center"]13643[/TD]
[TD="align: center"]0[/TD]
[TD="align: center"]-4[/TD]
[TD="align: center"]8[/TD]
[TD="align: center"]-13[/TD]
[TD="align: center"]17[/TD]
[TD="align: center"]-18[/TD]
[TD="align: center"]19[/TD]
[TD="align: center"]13643[/TD]
[TD="align: center"]-1[/TD]
[TD="align: center"]-5[/TD]
[TD="align: center"]7[/TD]
[TD="align: center"]-14[/TD]
[TD="align: center"]16[/TD]
[TD="align: center"]18[/TD]
[TD="align: center"]-19[/TD]
[TD="align: center"]13643[/TD]
[TD="align: center"]-3[/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD="align: center"]13644[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]-4[/TD]
[TD="align: center"]12[/TD]
[TD="align: center"]13[/TD]
[TD="align: center"]23[/TD]
[TD="align: center"]27[/TD]
[TD="align: center"]40[/TD]
[TD="align: center"]13644[/TD]
[TD="align: center"]-2[/TD]
[TD="align: center"]7[/TD]
[TD="align: center"]8[/TD]
[TD="align: center"]-9[/TD]
[TD="align: center"]18[/TD]
[TD="align: center"]22[/TD]
[TD="align: center"]35[/TD]
[TD="align: center"]13644[/TD]
[TD="align: center"]-1[/TD]
[TD="align: center"]-2[/TD]
[TD="align: center"]9[/TD]
[TD="align: center"]-11[/TD]
[TD="align: center"]13[/TD]
[TD="align: center"]-18[/TD]
[TD="align: center"]26[/TD]
[TD="align: center"]13644[/TD]
[TD="align: center"]5[/TD]
[/TR]
[TR]
[TD="align: center"]4[/TD]
[TD="align: center"]13645[/TD]
[TD="align: center"]13[/TD]
[TD="align: center"]18[/TD]
[TD="align: center"]19[/TD]
[TD="align: center"]25[/TD]
[TD="align: center"]28[/TD]
[TD="align: center"]31[/TD]
[TD="align: center"]43[/TD]
[TD="align: center"]13645[/TD]
[TD="align: center"]6[/TD]
[TD="align: center"]11[/TD]
[TD="align: center"]12[/TD]
[TD="align: center"]18[/TD]
[TD="align: center"]21[/TD]
[TD="align: center"]24[/TD]
[TD="align: center"]36[/TD]
[TD="align: center"]13645[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]-3[/TD]
[TD="align: center"]9[/TD]
[TD="align: center"]12[/TD]
[TD="align: center"]15[/TD]
[TD="align: center"]27[/TD]
[TD="align: center"]13645[/TD]
[TD="align: center"]1[/TD]
[/TR]
[TR]
[TD="align: center"]5[/TD]
[TD="align: center"]13646[/TD]
[TD="align: center"]0[/TD]
[TD="align: center"]-5[/TD]
[TD="align: center"]6[/TD]
[TD="align: center"]7[/TD]
[TD="align: center"]-9[/TD]
[TD="align: center"]14[/TD]
[TD="align: center"]24[/TD]
[TD="align: center"]13646[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]-5[/TD]
[TD="align: center"]9[/TD]
[TD="align: center"]-10[/TD]
[TD="align: center"]-14[/TD]
[TD="align: center"]19[/TD]
[TD="align: center"]13646[/TD]
[TD="align: center"]0[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]-6[/TD]
[TD="align: center"]8[/TD]
[TD="align: center"]-11[/TD]
[TD="align: center"]-15[/TD]
[TD="align: center"]18[/TD]
[TD="align: center"]13646[/TD]
[TD="align: center"]2[/TD]
[/TR]
[TR]
[TD="align: center"]6[/TD]
[TD="align: center"]13647[/TD]
[TD="align: center"]6[/TD]
[TD="align: center"]17[/TD]
[TD="align: center"]21[/TD]
[TD="align: center"]22[/TD]
[TD="align: center"]27[/TD]
[TD="align: center"]37[/TD]
[TD="align: center"]40[/TD]
[TD="align: center"]13647[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]13[/TD]
[TD="align: center"]17[/TD]
[TD="align: center"]18[/TD]
[TD="align: center"]23[/TD]
[TD="align: center"]33[/TD]
[TD="align: center"]36[/TD]
[TD="align: center"]13647[/TD]
[TD="align: center"]-3[/TD]
[TD="align: center"]8[/TD]
[TD="align: center"]12[/TD]
[TD="align: center"]13[/TD]
[TD="align: center"]18[/TD]
[TD="align: center"]28[/TD]
[TD="align: center"]31[/TD]
[TD="align: center"]13647[/TD]
[TD="align: center"]2[/TD]
[/TR]
[TR]
[TD="align: center"]7[/TD]
[TD="align: center"]13648[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]4[/TD]
[TD="align: center"]-5[/TD]
[TD="align: center"]6[/TD]
[TD="align: center"]11[/TD]
[TD="align: center"]24[/TD]
[TD="align: center"]30[/TD]
[TD="align: center"]13648[/TD]
[TD="align: center"]0[/TD]
[TD="align: center"]-5[/TD]
[TD="align: center"]-7[/TD]
[TD="align: center"]-10[/TD]
[TD="align: center"]13[/TD]
[TD="align: center"]-16[/TD]
[TD="align: center"]19[/TD]
[TD="align: center"]13648[/TD]
[TD="align: center"]-4[/TD]
[TD="align: center"]9[/TD]
[TD="align: center"]-9[/TD]
[TD="align: center"]-11[/TD]
[TD="align: center"]-14[/TD]
[TD="align: center"]15[/TD]
[TD="align: center"]-20[/TD]
[TD="align: center"]13648[/TD]
[TD="align: center"]-5[/TD]
[/TR]
[TR]
[TD="align: center"]8[/TD]
[TD="align: center"]13649[/TD]
[TD="align: center"]-1[/TD]
[TD="align: center"]-5[/TD]
[TD="align: center"]7[/TD]
[TD="align: center"]15[/TD]
[TD="align: center"]27[/TD]
[TD="align: center"]34[/TD]
[TD="align: center"]38[/TD]
[TD="align: center"]13649[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]-7[/TD]
[TD="align: center"]9[/TD]
[TD="align: center"]-11[/TD]
[TD="align: center"]21[/TD]
[TD="align: center"]28[/TD]
[TD="align: center"]32[/TD]
[TD="align: center"]13649[/TD]
[TD="align: center"]-2[/TD]
[TD="align: center"]6[/TD]
[TD="align: center"]-10[/TD]
[TD="align: center"]-14[/TD]
[TD="align: center"]18[/TD]
[TD="align: center"]25[/TD]
[TD="align: center"]29[/TD]
[TD="align: center"]13649[/TD]
[TD="align: center"]4[/TD]
[/TR]
[TR]
[TD="align: center"]9[/TD]
[TD="align: center"]13650[/TD]
[TD="align: center"]8[/TD]
[TD="align: center"]15[/TD]
[TD="align: center"]18[/TD]
[TD="align: center"]23[/TD]
[TD="align: center"]29[/TD]
[TD="align: center"]30[/TD]
[TD="align: center"]36[/TD]
[TD="align: center"]13650[/TD]
[TD="align: center"]4[/TD]
[TD="align: center"]11[/TD]
[TD="align: center"]14[/TD]
[TD="align: center"]19[/TD]
[TD="align: center"]25[/TD]
[TD="align: center"]26[/TD]
[TD="align: center"]32[/TD]
[TD="align: center"]13650[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]-4[/TD]
[TD="align: center"]6[/TD]
[TD="align: center"]11[/TD]
[TD="align: center"]17[/TD]
[TD="align: center"]18[/TD]
[TD="align: center"]24[/TD]
[TD="align: center"]13650[/TD]
[TD="align: center"]-2[/TD]
[/TR]
[TR]
[TD="align: center"]10[/TD]
[TD="align: center"]13651[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]-2[/TD]
[TD="align: center"]-6[/TD]
[TD="align: center"]21[/TD]
[TD="align: center"]28[/TD]
[TD="align: center"]34[/TD]
[TD="align: center"]39[/TD]
[TD="align: center"]13651[/TD]
[TD="align: center"]-6[/TD]
[TD="align: center"]-9[/TD]
[TD="align: center"]-13[/TD]
[TD="align: center"]14[/TD]
[TD="align: center"]21[/TD]
[TD="align: center"]27[/TD]
[TD="align: center"]32[/TD]
[TD="align: center"]13651[/TD]
[TD="align: center"]-9[/TD]
[TD="align: center"]11[/TD]
[TD="align: center"]-12[/TD]
[TD="align: center"]-16[/TD]
[TD="align: center"]18[/TD]
[TD="align: center"]24[/TD]
[TD="align: center"]29[/TD]
[TD="align: center"]13651[/TD]
[TD="align: center"]6[/TD]
[/TR]
[TR]
[TD="align: center"]11[/TD]
[TD="align: center"]13652[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]4[/TD]
[TD="align: center"]10[/TD]
[TD="align: center"]22[/TD]
[TD="align: center"]24[/TD]
[TD="align: center"]34[/TD]
[TD="align: center"]44[/TD]
[TD="align: center"]13652[/TD]
[TD="align: center"]0[/TD]
[TD="align: center"]-1[/TD]
[TD="align: center"]6[/TD]
[TD="align: center"]18[/TD]
[TD="align: center"]20[/TD]
[TD="align: center"]30[/TD]
[TD="align: center"]40[/TD]
[TD="align: center"]13652[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]-3[/TD]
[TD="align: center"]-4[/TD]
[TD="align: center"]15[/TD]
[TD="align: center"]17[/TD]
[TD="align: center"]27[/TD]
[TD="align: center"]37[/TD]
[TD="align: center"]13652[/TD]
[TD="align: center"]-3[/TD]
[/TR]
[TR]
[TD="align: center"]12[/TD]
[TD="align: center"]13653[/TD]
[TD="align: center"]16[/TD]
[TD="align: center"]27[/TD]
[TD="align: center"]30[/TD]
[TD="align: center"]37[/TD]
[TD="align: center"]38[/TD]
[TD="align: center"]39[/TD]
[TD="align: center"]41[/TD]
[TD="align: center"]13653[/TD]
[TD="align: center"]15[/TD]
[TD="align: center"]26[/TD]
[TD="align: center"]29[/TD]
[TD="align: center"]36[/TD]
[TD="align: center"]37[/TD]
[TD="align: center"]38[/TD]
[TD="align: center"]40[/TD]
[TD="align: center"]13653[/TD]
[TD="align: center"]9[/TD]
[TD="align: center"]20[/TD]
[TD="align: center"]23[/TD]
[TD="align: center"]30[/TD]
[TD="align: center"]31[/TD]
[TD="align: center"]32[/TD]
[TD="align: center"]34[/TD]
[TD="align: center"]13653[/TD]
[TD="align: center"]-3[/TD]
[/TR]
[TR]
[TD="align: center"]13[/TD]
[TD="align: center"]13654[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]-4[/TD]
[TD="align: center"]-8[/TD]
[TD="align: center"]-11[/TD]
[TD="align: center"]15[/TD]
[TD="align: center"]25[/TD]
[TD="align: center"]26[/TD]
[TD="align: center"]13654[/TD]
[TD="align: center"]4[/TD]
[TD="align: center"]-8[/TD]
[TD="align: center"]14[/TD]
[TD="align: center"]15[/TD]
[TD="align: center"]-15[/TD]
[TD="align: center"]-19[/TD]
[TD="align: center"]-22[/TD]
[TD="align: center"]13654[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]11[/TD]
[TD="align: center"]-11[/TD]
[TD="align: center"]12[/TD]
[TD="align: center"]-18[/TD]
[TD="align: center"]-22[/TD]
[TD="align: center"]-25[/TD]
[TD="align: center"]13654[/TD]
[TD="align: center"]4[/TD]
[/TR]
[TR]
[TD="align: center"]14[/TD]
[TD="align: center"]13655[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]-5[/TD]
[TD="align: center"]-8[/TD]
[TD="align: center"]9[/TD]
[TD="align: center"]-10[/TD]
[TD="align: center"]30[/TD]
[TD="align: center"]33[/TD]
[TD="align: center"]13655[/TD]
[TD="align: center"]0[/TD]
[TD="align: center"]6[/TD]
[TD="align: center"]-8[/TD]
[TD="align: center"]-11[/TD]
[TD="align: center"]-13[/TD]
[TD="align: center"]27[/TD]
[TD="align: center"]30[/TD]
[TD="align: center"]13655[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]-4[/TD]
[TD="align: center"]-12[/TD]
[TD="align: center"]-15[/TD]
[TD="align: center"]-17[/TD]
[TD="align: center"]23[/TD]
[TD="align: center"]26[/TD]
[TD="align: center"]13655[/TD]
[TD="align: center"]-5[/TD]
[/TR]
[TR]
[TD="align: center"]15[/TD]
[TD="align: center"]13656[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]4[/TD]
[TD="align: center"]8[/TD]
[TD="align: center"]22[/TD]
[TD="align: center"]27[/TD]
[TD="align: center"]32[/TD]
[TD="align: center"]33[/TD]
[TD="align: center"]13656[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]6[/TD]
[TD="align: center"]20[/TD]
[TD="align: center"]25[/TD]
[TD="align: center"]30[/TD]
[TD="align: center"]31[/TD]
[TD="align: center"]13656[/TD]
[TD="align: center"]-1[/TD]
[TD="align: center"]-2[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]17[/TD]
[TD="align: center"]22[/TD]
[TD="align: center"]27[/TD]
[TD="align: center"]28[/TD]
[TD="align: center"]13656[/TD]
[TD="align: center"]-5[/TD]
[/TR]
[TR]
[TD="align: center"]16[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[/TR]
[TR]
[TD="align: center"]17[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD="align: center"]
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: center"]18[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Last edited:
Upvote 0
What's wrong with the way your doing it?
 
Upvote 0
Hi Fluff,
There's nothing wrong with it as such, I just like to eliminate things like copy and paste, select etc... to make things run more smoothly. Do you have any suggestions?

regards
 
Last edited:
Upvote 0
Leave as-is, other than adding this line at the end
Code:
Application.CutCopyMode = False
 
Upvote 0
Ok will do :) it was giving me a headache anyway lol

Thank you Fluff
 
Last edited:
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,242
Members
452,623
Latest member
russelllowellpercy

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