title: Determine if table is empty, then skip rest of macro
body: <p>The code below is what I used to compare entries between two tabs on a worksheet. There is a helper column on the table object OpenComplaints labeled CCMS Notification. It searches for a match on the table object OpenQns. If there is no match it returns #N/A.</p>
  
  <p>The purpose of this macro is to autofilter column CCMS Notification on table OpenComplaints for #N/A, then copy over the DataBodyRange and paste these results onto a third tab. It then deletes the entries from OpenComplaints that were copied over.</p>
  
  <p>This all works great. However it breaks down if the table is empty. I want this to skip the macro if the table is empty. I've spent a few hours trying many examples from google and stackoverflow and I just can't seem to get any examples to work, so I apologize if this has been asked elsewhere but I can't seem to get other people's code to work. Currently, if the table is empty it selects the entire table (even when autofiltered) and then deletes the entries. </p>
  
  <p>Ideally, I'd like to use as many structured references as possible as the risk of people adding or removing columns is high on this worksheet.</p>
  
  <p>This is my code</p>
  
  <pre><code>Sub DeleteClosedQns()
  '
  ' DeleteClosedQns Macro
  
  If Range("D9").Value = "" Then
  Dim response As VbMsgBoxResult
  response = MsgBox("Previous step is not marked as complete. Proceed?", vbYesNo)
  If response = vbNo Then
      Exit Sub
  End If
  End If
  
  'Checks if the previous step was completed, as marked by a X.
  
  Sheets("BP -Tracker - Open Complaints").Select
  Sheets("BP -Tracker - Open Complaints").ListObjects("OpenComplaints").Range.AutoFilter Field:=2, Criteria1:= _
      "#N/A"
  Sheets("BP -Tracker - Open Complaints").ListObjects("OpenComplaints").DataBodyRange.Copy
  
  ' Sets AutoFilter to #N/A, then copies the table body
  
  Sheets("YTD History Closed").Select
  With activesheets
  Dim LastRow As Long
      LastRow = Sheets("YTD History Closed").ListObjects("ClosedQns").Range.Columns(4).Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
  End With
  
  Range("A" &amp; LastRow).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
      :=False, Transpose:=False
  
  ' Navigates to the History Closed tab, calculates the last row used
  ' Then pastes with special values
  
  Sheets("BP -Tracker - Open Complaints").Select
  Sheets("BP -Tracker - Open Complaints").ListObjects("OpenComplaints").DataBodyRange.ClearContents
  
  ' Selects the entries that have been copied over, then deletes them
  
  If Sheets("BP -Tracker - Open Complaints").ListObjects("OpenComplaints").ShowAutoFilter Then
      Sheets("BP -Tracker - Open Complaints").ListObjects("OpenComplaints").Range.AutoFilter
  End If
  
  ' Removes the data filter
  
  Sheets("Instructions").Select
  Range("D10", "D10").Value = "X"
  ' Marks the step as complete with an X
  
  End Sub
  </code></pre>
  
  <p>edit: @soulshined. I'm glad it's just simple logic validation. However I've mentioned that I'm having trouble with it. Please don't disregard my question just because it's simple to you.</p>
  
  <p>@bigben sorry yes, I'm copying only the filtered data. Then later deleting the filtered data. It only copies the entire range if there are no results from autofilter, which is an error I'm trying to avoid.</p>
  
  <p>I tried CountA with the following test code
       Sheets("BP -Tracker - Open Complaints").ListObjects("OpenComplaints").Range.AutoFilter Field:=2, Criteria1:= _
          "#N/A"</p>
  
  <pre><code>If WorksheetFunction.CountA(Range("OpenComplaints[CCMS Notification]")) &gt; 0 Then
  MsgBox ("&gt; 0")
  End If
  If WorksheetFunction.CountA(Range("OpenComplaints[CCMS Notification]")) = 0 Then
  MsgBox ("Empty")
  End If
  </code></pre>
  
  <p>It's not actually telling me if a filtered table is empty. It seems to count even hidden columns, as my table OpenComplaints has no "#N/A" entries and is empty when I apply that filter. XlCellTypeVisible doesn't appear to work with CountA.</p>
  
  <p>Thank you for showing me that other question, however the fundamental question is not a duplicate.</p>