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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Try the following

VBA Code:
Sub copy3171()
    With Sheet1.Cells(1, 1).CurrentRegion
        .AutoFilter 1, "3171"
        .Copy Sheet2.Cells(1)
        .AutoFilter
    End With
End Sub
 
Upvote 0
Try the following

VBA Code:
Sub copy3171()
    With Sheet1.Cells(1, 1).CurrentRegion
        .AutoFilter 1, "3171"
        .Copy Sheet2.Cells(1)
        .AutoFilter
    End With
End Sub

hi kevin, all this is doing is pasting the cell a1 into my second sheet
 
Upvote 0
OK, try this

VBA Code:
Sub copy3171()
    With Sheet1.Range("A:A")
        .AutoFilter 1, "3171"
        .Copy Sheet2.Cells(1)
        .AutoFilter
    End With
End Sub
 
Upvote 0
OK, try this

VBA Code:
Sub copy3171()
    With Sheet1.Range("A:A")
        .AutoFilter 1, "3171"
        .Copy Sheet2.Cells(1)
        .AutoFilter
    End With
End Sub
i am still only getting the first cell of column a in sheet 1 in column a of sheet 2, all other cells of sheet 1 with value 3171 arent showing up
 
Upvote 0
OK, I can't go any further unless you post your actual data. Both codes suggested work for me, but I'm only guessing what your data looks like.
 
Upvote 0
111 3171
222 3171
333 1000
444 1000
555 3171

i would want the resulting column to look like this:
111 3171
222 3171
555 3171
 
Upvote 0
OK, I can't go any further unless you post your actual data. Both codes suggested work for me, but I'm only guessing what your data looks like.
this data is all i one column
 
Upvote 0
I don't know how your original code could have worked with the data you posted, however, this should work with a wildcard:

VBA Code:
Sub copy3171()
    With Sheet1.Cells(1, 1).CurrentRegion
        .AutoFilter 1, "*3171"
        .Copy Sheet2.Cells(1)
        .AutoFilter
    End With
End Sub
 
Upvote 0
I don't know how your original code could have worked with the data you posted, however, this should work with a wildcard:

VBA Code:
Sub copy3171()
    With Sheet1.Cells(1, 1).CurrentRegion
        .AutoFilter 1, "*3171"
        .Copy Sheet2.Cells(1)
        .AutoFilter
    End With
End Sub
thank you so much for you help! it worked perfectly
however, sometimes i have other data in sheet 1 that i do not want to filter. how do i specify this code to just column A in sheet 1? i also named this column Table4, if that helps
 
Upvote 0

Forum statistics

Threads
1,214,791
Messages
6,121,611
Members
449,038
Latest member
apwr

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