stop macro if table is no data

mark692

Active Member
Joined
Feb 27, 2015
Messages
321
Office Version
  1. 2016
Platform
  1. Windows
i have this code that will filter a row on my table named "Table5" i want to stop the code if the Field 2 has no data, is that possible? thanks!

Sub Save_Detergent() Dim wbk As Workbook
Dim Fname As String
Dim pth As String
Dim Addr As String

pth = "C:\Users"
Fname = "Detergent.xlsm"
ActiveSheet.ListObjects("Table5").Range.AutoFilter Field:=2, Criteria1:= _
">0"
Range("Table5[[Name]:[QTY]]").Copy
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Hi

replace
Code:
ActiveSheet.ListObjects("Table5").Range.AutoFilter Field:=2, Criteria1:=">0"
with
Code:
With ActiveSheet.ListObjects("Table5")
    .Range.AutoFilter Field:=2, Criteria1:=">0"
    If .Range.SpecialCells(xlCellTypeVisible).Rows.Count = 1 Then Exit Sub
End With
 
Upvote 0
Hi

replace
Code:
ActiveSheet.ListObjects("Table5").Range.AutoFilter Field:=2, Criteria1:=">0"
with
Code:
With ActiveSheet.ListObjects("Table5")
    .Range.AutoFilter Field:=2, Criteria1:=">0"
    If .Range.SpecialCells(xlCellTypeVisible).Rows.Count = 1 Then Exit Sub
End With


thank you sir, hmm what if i change it, instead of stopping the code, it will just do nothing if field 2 is empty?
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

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