DataBodyRange lost after adding new column to listobject

mdwasim

New Member
Joined
Dec 31, 2019
Messages
14
Office Version
  1. 2016
Platform
  1. Windows
Hello Experts,
I am not able to figure out why the Run-time error.
For every row in the 1st table, a new table is created.
The new tables will consist of the number of rows as per the #Count column from 1st table.
Also, a new column will be added at the end of the table if column "t1col5 to t1col8" value is "Yes".

Upon, execute, the table to be created is copied from Templates sheet.
If the #Count is more than "1" it works fine!!.
1608.jpg
When #Count is "1" i.e., the new table will have 1 Row, and this is where the with block of Range.validation throws error 91.
I tried quite a few tweaks, but none worked.
1609.jpg

With 4-5 hours of head scratching, What I understood is a single Cell Column is not considered as "DataBodyRange"
1610.jpg
If thats the case, why is it so and how to work around this issue?

It would be really helpful if someone can take a look at the code and point me in right direction.

Thanks.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Looking at the number of unanswered questions, I don't see any time soon I will be getting a review
 
Upvote 0
With 4-5 hours of head scratching, What I understood is a single Cell Column is not considered as "DataBodyRange"
1610.jpg
If thats the case, why is it so and how to work around this issue?

Maybe some facts about tables will help you. DataBodyRange is Nothing when the table has no data rows. An empty table has a header row (HeaderRowRange) and 1 row of empty cells below the header row, so although the table appears to have 1 data row, that data row is empty and therefore DataBodyRange is Nothing. DataBodyRange is defined (i.e. not Nothing) only when the table has at least 1 row of data.
 
Upvote 1
Solution
Wow, this was really a new thing for me. Never knew that is the case.
Thank you, John!! For this information.

A couple of work around that comes to my mind are
1. To use Table range and offset/resize by 1 row.
2. Add a "space" to the first cell of the row in of the template table and call a function to clear the DataBodRrange on each table as the last step of the process.

I do see additional overhead of calling a function #2 as compared to #1 i.e., doing it the right way (if it works)
I will give it a try.
 
Upvote 0
I haven't looked at your code, so I don't know what the correct approach should be. One way is an If statement which checks if DataBodyRange Is Nothing:

VBA Code:
    Set table1 = ActiveSheet.ListObjects("Table1")
    If table1.DataBodyRange Is Nothing Then
        'Table1 has 1 'data' row which is empty
    Else
        ':
    End If
 
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,223
Members
452,620
Latest member
dsubash

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top