Help Required with VBA Code!

micropscotts

New Member
Joined
Aug 6, 2014
Messages
1
Hi guys,

I have a spreadsheet with several sheets which I am having a few problems with. Basically I have set up the below code so that VBA will apply an autofilter which looks for a certain criteria in a column and then cuts and pastes the relevant row to the next sheet before deleting the row in the first sheet and moving the rows up. The criteria that the autofilter looks for is "Yes."

Code:
Option ExplicitSub Button11_Click()
     
    Application.ScreenUpdating = False
    Columns(14).AutoFilter 1, "Yes" '// Applies an autofilter to the 14th column (Col N), filters for value "Yes"
    With Range("a2", Range("n" & Rows.Count).End(3)) '// This range is all the data, when using autofilter no need to specify visible cells
        .Copy Sheet5.Cells(Rows.Count, 1).End(3).Offset(1) '// Copies all the rows on Sheet4 which were filtered, pastes to first available row on Sheet5
        .EntireRow.Delete '// Deletes all the rows on Sheet3 which were filtered
    End With
    Columns(14).AutoFilter '// Removes the autofilter
    Application.ScreenUpdating = True
     
End Sub

Basically the problem I am encountering is that when I click the update button, it cuts and pastes the column header as well as the update button into the next sheet which obviously I don't want it to do.

Can anyone please point me in the right direction with this?

Many thanks
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
I don't have an answer for you, but it might be worth just recording the macro, and then butchering that code as you've obviously got something a tad weird going on!
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,934
Members
449,094
Latest member
teemeren

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