Issue with filters in VBA

Tucker92

Board Regular
Joined
Jun 7, 2018
Messages
53
I'm currently designing macros to help set up carry over sheets within my business. The issue i have is that if the filter choice is not available then it just selects the one that is and copy's. How can i skip this section if nothing is available.

Here is my code

Sub Copy_RSVDustol_Into_VacAC()


Windows("Vac AC.xlsm").Activate
Sheets("RSV&Dustol").Select


Windows("Carry Over.xlsm").Activate
Sheets("Vac A").Select
ActiveSheet.ListObjects("Table6").Range.AutoFilter Field:=13, Criteria1:= _
"RSV / DUSTROL"

Range("A2:B100").Select
Selection.Copy
Windows("Vac AC.xlsm").Activate
Sheets("RSV&Dustol").Select
Range("A2").Select
ActiveSheet.Paste
Windows("Carry Over.xlsm").Activate
Range("D2:F100").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Vac AC.xlsm").Activate
Range("D2").Select
ActiveSheet.Paste
Columns("C:C").EntireColumn.AutoFit
Windows("Carry Over.xlsm").Activate
Sheets("Vac A").Select
ActiveSheet.ListObjects("Table6").Range.AutoFilter Field:=13
End Sub
 
Last edited:

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Do you mean if the cell you are filtering on is empty then don't continue? If so you could use an If and IsEmpty. An example of this is shown below (If this is something you can work with it will need to be adapted inside your code):

Check if "Work Issue" has content before proceeding
'If empty show message and stop the process
If IsEmpty(Sheets("Work Issue").Range("M2")) = True Then
MsgBox "M2 is empty do you want to continue", vbOKOnly
 
Last edited:
Upvote 0
Only issue is that the sheet wont be completely empty as i have a table which gets populated by the filtered results.

How would i skip the copy and paste section as i am calling in different macros and this is only one of many?

I dont want it to completely stop if it is false just skip past the copy and paste so that the next macro can carry on.

Would i just be able to change the MsgBox section to a go to next macro and could i use an "Else" for it to carry on the rest of the macro

I'm very new to vba and am self taught so not very confident yet. Any help is greatly appreciated. Thank you
 
Upvote 0
You could add an if statement stating if the cell is empty go to the next macro or if not continue the process. An example of this sort of thing is shown below, just a basic IF statment.

Sub skipMsgbox()
If Range("A3") = "" Then
MsgBox "The cell is empty"
Else: MsgBox "The cell content is " & Range("A3").Value
End If
End Sub
 
Upvote 0
The table that i am filtering contains other information though from another area and when i check to see if the cell is empty then it is picking up the other information in there. This information is further down the list but not always in the same place so i cant set a place the check if it is empty.
 
Upvote 0

Forum statistics

Threads
1,224,837
Messages
6,181,255
Members
453,028
Latest member
letswriteafairytale

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