Copy rows based on column value on button click

StacyC

New Member
Joined
Apr 4, 2019
Messages
3
Hi everyone,

Long time lurker, first time poster - I'm not great with VBA to begin with and I'm at my wits end, so I'm hoping someone can help me.

I am trying to create a button on Sheet1 that, when pressed, will search for "X" in Column F of Sheet2 and copy the full contents of that row onto Sheet3. You following me so far?

I'm using this code, pilfered from the internet:

Code:
Private Sub Create_Click()

Application.ScreenUpdating = False


With Sheet2
    .AutoFilterMode = False
    With Range("F1", Range("F" & Rows.Count).End(xlUp))
        .AutoFilter 1, "X"
        On Error Resume Next
        .Offset(1).EntireRow.Copy Sheet3.Range("A" & Rows.Count).End(xlUp).Offset(1)
    End With
    .AutoFilterMode = False
End With


Application.ScreenUpdating = True
Sheet3.Select


End Sub

When I click the button, I get the following error:

Run-time error '1004':
AutoFilter method of Range class failed

I've tried everything I can think of but I'm stumped. I'm sure it's probably something very obvious, but just not to me. Can anyone advise? Thanks!
 

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.
Hello Stacy,

Your code works just fine for me. Are you sure that your headings are in Row1 with data starting in Row2?

Cheerio,
vcoolio.
 
Upvote 0
.......or you could try and fully qualify sheet2 as the source sheet:-


Code:
Private Sub Create_Click()

Application.ScreenUpdating = False

    With Sheet2.Range("F1", Sheet2.Range("F" & Sheet2.Rows.Count).End(xlUp))
        .AutoFilter 1, "X"
        .Offset(1).EntireRow.Copy Sheet3.Range("A" & Rows.Count).End(xlUp).Offset(1)
        .AutoFilter
    End With

Application.ScreenUpdating = True

Sheet3.Select

End Sub

I hope that this helps.

Cheerio,
vcoolio.
 
Upvote 0
You're welcome Stacy. I'm glad that I was able to help.
Thanks for the feed-back.

Cheerio,
vcoolio.
 
Upvote 0

Forum statistics

Threads
1,216,533
Messages
6,131,216
Members
449,636
Latest member
ajdebm

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