If I am looping through my sheets and want to test if any ListObjects exist in the given sheet, how do I do this? I tried this:
Dim daysoftheweek As Worksheet
For Each daysoftheweek In Sheets
If Not daysoftheweek.ListObjects Is Nothing Then
'Do Something Here - Only If The Sheet Contains A List Object
End If
Next
But the IF conditional block still ran even when the sheet did not contain a ListObject.
Worksheet.ListObjects
is a collection so it isn't Nothing
. Like Paul Bica commented, you want to count how many objects are in the collection. Try this:
Dim daysoftheweek As Worksheet
For Each daysoftheweek In Sheets
If daysoftheweek.ListObjects.Count > 0 Then
'Do Something Here - Only If The Sheet Contains A List Object
End If
Next
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With