Hi all,
So I have this following code (piece):
Which was working perfectly until I had 5 tables and the last one was the "BLANKTable" but I had to add a new table, to which the interior colour change should apply.. but if the BLANKTable is empty then the code throws an error. (and I realized other tables may end up empty as well before this step, so this code piece is really not right)
I can see why.. but I don't know how to loop through all the tables except for the ones that's databody range is empty.. which is what I would need here I think. Could someone help with this?
Question posted on Excelforum as well. Link: https://www.excelforum.com/excel-pr...-in-vba-igrnore-empty-tables.html#post5120216
So I have this following code (piece):
![File-Copy-icon.png](/board/proxy.php?image=http%3A%2F%2Ficons.iconarchive.com%2Ficons%2Fdouble-j-design%2Fravenna-3d%2F24%2FFile-Copy-icon.png&hash=7af35a7272028e9c5ca14222f1d8ed66)
Code:
<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">
Dim i As Long
Dim LOC As Long
If Not Sheet4.ListObjects("BLANKTable").DataBodyRange Is Nothing Then
LOC = Sheet4.ListObjects.Count
ElseIf Sheet4.ListObjects("BLANKTable").DataBodyRange Is Nothing Then
LOC = Sheet4.ListObjects.Count - 1
End If
For i = 1 To LOC
Sheet4.ListObjects(i).DataBodyRange.ClearFormats
Sheet4.ListObjects(i).DataBodyRange.ClearFormats
Sheet4.ListObjects(i).DataBodyRange.ClearFormats
Sheet4.ListObjects(i).DataBodyRange.ClearFormats
Sheet4.ListObjects(i).ListColumns("One of the columns").DataBodyRange.Interior.Color = RGB(207, 207, 237)
Sheet4.ListObjects(i).ListColumns("Another one").DataBodyRange.Interior.Color = RGB(245, 212, 231)
Sheet4.ListObjects(i).ListColumns("A column").DataBodyRange.Interior.Color = RGB(220, 209, 233)
Sheet4.ListObjects(i).ListColumns("A different column").DataBodyRange.Interior.Color = RGB(220, 209, 233)
Next i</code>
Which was working perfectly until I had 5 tables and the last one was the "BLANKTable" but I had to add a new table, to which the interior colour change should apply.. but if the BLANKTable is empty then the code throws an error. (and I realized other tables may end up empty as well before this step, so this code piece is really not right)
I can see why.. but I don't know how to loop through all the tables except for the ones that's databody range is empty.. which is what I would need here I think. Could someone help with this?
Question posted on Excelforum as well. Link: https://www.excelforum.com/excel-pr...-in-vba-igrnore-empty-tables.html#post5120216
Last edited: