Filter button keeps getting deleted

D_Holmes

New Member
Joined
Sep 18, 2020
Messages
32
Office Version
  1. 2013
Platform
  1. Windows
Hi All,

I am trying to run a macro that will autofilter my table and then copy the filtered data to another sheet. However, when the macro gets to a specific part of the code, I get an error message and then realize that its because the filter button under one of the filter options is deleted. When it deletes, the macro has no way of filtering the information in the column. Can someone look at my macro and let me know what I am doing wrong? Thanks.

'Paste HCH HCH PATIENT ACCESS
Rich (BB code):
Next6:
Worksheets("Disaster110220").Range("A1:P1").AutoFilter Field:=14, Criteria1:="HCH HCH PATIENT ACCESS"
Worksheets("Disaster110220").Range("A1:P1").AutoFilter Field:=9, Criteria1:="ACTIVE"

    Worksheets("Disaster110220").Range("a2:p" & lr).SpecialCells(xlCellTypeVisible).Copy
    Worksheets("HCH HCH PATIENT ACCESS").Range("a2").PasteSpecial Paste:=xlPasteAll
    Application.CutCopyMode = False

Worksheets("Disaster110220").Range("A1:P1").AutoFilter Field:=9, Criteria1:="ONCALL", VisibleDropDown:=False

On Error GoTo Next7

    Worksheets("Disaster110220").Range("a2:p" & lr).SpecialCells(xlCellTypeVisible).Copy
    Worksheets("HCH HCH PATIENT ACCESS").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteAll
    Application.CutCopyMode = False

Next7:
Worksheets("Disaster110220").Range("A1:P1").AutoFilter Field:=9, Criteria1:="LEAVE", VisibleDropDown:=False

On Error GoTo Next8

   Worksheets("Disaster110220").Range("a2:p" & lr).SpecialCells(xlCellTypeVisible).Copy (I get the error here, however the code is the same for all subsequent sections)
    Worksheets("HCH HCH PATIENT ACCESS").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteAll
    Application.CutCopyMode = False
 
Last edited by a moderator:

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.
What error message do you get?
 
Upvote 0
Your error handling is wrong. As soon as one error occurs, none of your subsequent On Error statements will work and you will simply have an unhandled error - eg if there are no visible cells.
 
Upvote 0
Your error handling is wrong. As soon as one error occurs, none of your subsequent On Error statements will work and you will simply have an unhandled error - eg if there are no visible cells.
Ah okay. Do you know how I can fix this?
 
Upvote 0
How about
VBA Code:
With Worksheets("Disaster110220")
   .Range("A1:P1").AutoFilter Field:=14, Criteria1:="HCH HCH PATIENT ACCESS"
   .Range("A1:P1").AutoFilter Field:=9, Criteria1:="ACTIVE"
   .AutoFilter.Range.Offset(1).Copy
    Worksheets("HCH HCH PATIENT ACCESS").Range("a2").PasteSpecial Paste:=xlPasteAll
    Application.CutCopyMode = False

   .Range("A1:P1").AutoFilter Field:=9, Criteria1:="ONCALL", VisibleDropDown:=False
    .AutoFilter.Range.Offset(1).Copy
    Worksheets("HCH HCH PATIENT ACCESS").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteAll
    Application.CutCopyMode = False
   
   .Range("A1:P1").AutoFilter Field:=9, Criteria1:="LEAVE", VisibleDropDown:=False
   .AutoFilter.Range.Offset(1).Copy
    Worksheets("HCH HCH PATIENT ACCESS").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteAll
    Application.CutCopyMode = False
End With
 
Upvote 0
How about
VBA Code:
With Worksheets("Disaster110220")
   .Range("A1:P1").AutoFilter Field:=14, Criteria1:="HCH HCH PATIENT ACCESS"
   .Range("A1:P1").AutoFilter Field:=9, Criteria1:="ACTIVE"
   .AutoFilter.Range.Offset(1).Copy
    Worksheets("HCH HCH PATIENT ACCESS").Range("a2").PasteSpecial Paste:=xlPasteAll
    Application.CutCopyMode = False

   .Range("A1:P1").AutoFilter Field:=9, Criteria1:="ONCALL", VisibleDropDown:=False
    .AutoFilter.Range.Offset(1).Copy
    Worksheets("HCH HCH PATIENT ACCESS").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteAll
    Application.CutCopyMode = False
  
   .Range("A1:P1").AutoFilter Field:=9, Criteria1:="LEAVE", VisibleDropDown:=False
   .AutoFilter.Range.Offset(1).Copy
    Worksheets("HCH HCH PATIENT ACCESS").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteAll
    Application.CutCopyMode = False
End With
So I think its the error handling i am doing that is not correct. So, as i go through the different criteria, I am realizing that "ONCALL" AND "LEAVE" are not options for all of the fields. Which is why I need a correct error handling statement to skip over the data that is missing and proceed to the next criteria. I hope that made sense. I am having a hard time trying to articulate via messaging.
 
Upvote 0
With the code I just posted, you should not need any error handling to deal with having no filtered rows.
 
Upvote 0
I think that it is less to do with having filtered rows and more to do with there is just no data that matches that criteria ("HCH HCH PATIENT ACCESS" & "ONCALL" OR "LEAVE"). However, I will run this macro every month and that could change which is why I do not want to delete it out all together.
 
Upvote 0
Have you tried my suggestion?
 
Upvote 0

Forum statistics

Threads
1,214,998
Messages
6,122,639
Members
449,093
Latest member
Ahmad123098

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