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

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
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
I do not understand your question
 
Upvote 0

Forum statistics

Threads
1,214,652
Messages
6,120,747
Members
448,989
Latest member
mariah3

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