filtering a column and pasting the results

apor

New Member
Joined
Dec 20, 2021
Messages
25
Office Version
  1. 2016
Platform
  1. Windows
i have one column, column a, of which i want to copy the rows that contain the numbers 3171 and paste all of these rows into a new sheet.

i used this code before, and now that im trying to use it again its not working. all thats happening is that the first row with 3171 gets pasted into 300 rows of column a of sheet 2

Sub Paste3171
With Sheet1
.AutoFilterMode = False
With .Range("A1:A300")
.AutoFilter Field:=1, Criteria1:="3171"
.SpecialCells(xlCellTypeVisible).Copy Destination:=Sheet2.Range("A1:A300")
End With
End With

also, i would like to not just select a1:a300 in both sheets, but preferrably the entire column because i often have over 300 values
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Do not want to filter, or do not want to copy?
both, i figured it out using this code

Sub copy3171()
Set range_to_filter = Range("Table4")
range_to_filter.AutoFilter 1, "*3171"
range_to_filter.Copy Sheet2.Cells(1)
range_to_filter.AutoFilter
End Sub


thank you for your help!
 
Upvote 0
You're welcome and well done working it out - it's always more satisfying :)
 
Upvote 0

Forum statistics

Threads
1,215,256
Messages
6,123,913
Members
449,132
Latest member
Rosie14

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