Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Check if Table Databodyrange has value

I would like help in this section of my code where I want it to show a msgbox if the table already has data, but I am not able to set it. With my current code it shows the msg regardless of whether or not there is data in the table.

If Not ActiveSheet.ListObjects(1).DataBodyRange Is Nothing Then
    MsgBox "Table has data", vbInformation
    Exit Sub
End If

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Use WorksheetFunction.CountA to count the non-empty cells in the table body:

With ActiveSheet.ListObjects(1)
   If Not .DataBodyRange Is Nothing Then
       If WorksheetFunction.CountA(.DataBodyRange) > 0 Then
           MsgBox "Table has data", vbInformation
           Exit Sub
       End If
   End If
End With
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading