Determine if range has data
<p>The following code creates a chart from a named Range &quot;Table24&quot;.</p>
<p>There will be times when this table has no valid data and then I want the range of my dataset to be a cell with 0 and populate the chart with no data.</p>
<p>This is for the 4th out of 5 charts- using debug I determined that this is the code which crashes my Excel file every time it's run:</p>
<pre class="lang-vb prettyprint-override"><code>'//////////////////CHART 4 Creation //////////////////////////////
Set myChtRange = ws.Range(&quot;L43:R63&quot;)
' What range contains data for chart
 
If ws.Range(&quot;Table24&quot;).Rows.Count &gt; 0 Then
    Set myDataRange = ws.ListObjects(&quot;Table24&quot;).ListColumns(3).DataBodyRange
Else
    Set myDataRange = ws.Range(&quot;K1&quot;)
End If

' Cover chart range with chart
Set objChart = .ChartObjects.Add( _
    Left:=myChtRange.Left, Top:=myChtRange.Top, _
    Width:=myChtRange.Width, Height:=myChtRange.Height)
' Put all the right stuff in the chart
With objChart.Chart
    .ChartArea.AutoScaleFont = False
    .ChartType = xlColumnClustered
    .ChartStyle = 214
    .SetSourceData Source:=myDataRange
    .Parent.Name = &quot;Chart4&quot;
    .HasTitle = True
    .HasLegend = False
    .ChartTitle.Characters.Text = &quot;Most Tolerance Holds&quot;
    .ChartTitle.Font.Bold = True
    .ChartTitle.Font.Size = 15
  
    If ws.Range(&quot;Table24&quot;).Rows.Count &gt; 0 Then
        .SeriesCollection(1).XValues = ws.ListObjects(&quot;Table24&quot;).ListColumns(2).DataBodyRange
    Else
        .SeriesCollection(1).XValues = ws.Range(&quot;K1&quot;)
    End If

    With .Axes(xlCategory, xlPrimary)
        .HasTitle = True
        With .AxisTitle
            .Characters.Text = &quot; &quot;
            .Font.Size = 10
            .Font.Bold = True
        End With
    End With
    With .Axes(xlValue, xlPrimary)
        .HasTitle = True
        .DisplayUnit = none
        .HasDisplayUnitLabel = False
        .TickLabels.NumberFormat = &quot;#,##0.0&quot;
        With .AxisTitle
            .Characters.Text = &quot;Lines&quot;
            .Font.Size = 15
            .Font.Bold = True
        End With
    End With
End With
</code></pre>
<p>I tried:</p>
<pre class="lang-vb prettyprint-override"><code>If ws.ListObjects(&quot;Table24&quot;).DataBodyRange.Rows.Count &gt; 0 Then

If NOT ws.ListObjects(&quot;Table24&quot;).DataBodyRange Is Nothing Then
</code></pre>
<p>And even the IS Empty</p>
<p>I need help creating the argument when the table looks like this:<br />
<a href="https://i.stack.imgur.com/jY2vI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jY2vI.png" alt="enter image description here" /></a></p>
<p>The named range &quot;Table24&quot; does exist. The table has no data in it.<br />
<a href="https://i.stack.imgur.com/jpzyd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jpzyd.png" alt="enter image description here" /></a></p>