Selecting Part of a Column from a ListObject table in VBA...?

450nick

Well-known Member
Joined
May 11, 2009
Messages
507
Hi everyone!

I'm trying to select part of a table using VBA. Basically I'm using a loop to roll through each column of a table, and for certain columns I want to extract the body data (not the header), but only the cells that are populated. The cells will always be filled from the top, so I'm looking for row 2 to row x from the column. I have used the following formula to work out the number of items in the column (in this case 2 when excluding the header) out of the total column length of 10 plus the header.

r = Application.WorksheetFunction.CountA(Worksheets("Data").ListObjects("Scenario" & Scenario & "DC").ListColumns(i).Range)

How on earth do select row 2 to row 4 as a range to pull into a VBA array??
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I believe this will have everything you need
 
Upvote 0
I don't see anything in that website that covers this requirement?? I'm currently thinking of using redim preserve but I'm getting an error... Any ideas why??


VBA Code:
                r = Application.WorksheetFunction.CountA(Worksheets("Data").ListObjects("Scenario" & Scenario & "DC").ListColumns(i).DataBodyRange)
                
                Choices = Worksheets("Data").ListObjects("Scenario" & Scenario & "DC").ListColumns(i).DataBodyRange
                ReDim Preserve Choices(r)
 
Upvote 0
Any sample for helpers outside there to have more understanding on what you want to achieve?
 
Upvote 0

Forum statistics

Threads
1,214,950
Messages
6,122,428
Members
449,083
Latest member
Ava19

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