Creating array of selected columns from named table

Westbury

Board Regular
Joined
Jun 7, 2009
Messages
139
My fundamental question is how do I put columns 1, 7 & 8 from a named table into an array?

I've studied a similar question in Best way of putting various columns from a Table into an array and particularly the solution identified by Fluff
but keep getting a runtime error 9 subscript out of range.

My named table definitely exists but it appears that the vba doesn't recognise it. I'm using Excel 2013 if that is of significance.

This is the code so far..

VBA Code:
Sub ColumnsTable_To_Array()

Dim myTable As ListObject
Dim myArray As Variant

'Set path for Table variable
myArray = Worksheets("Data list").ListObjects("Data").Range

Erase myArray
End Sub

Thanks
Geoff
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Do you actually have a structured table, or just a named range?
 
Upvote 0
Yes but is it a structured table? If you select that name in the name manager, can you edit it?
 
Upvote 0
In that case it is not a table, which is why your code doesn't work.
Try
VBA Code:
myArray = Worksheets("Data list").Range("Data").Value2
 
Upvote 0
I thought having named the range with Name Manager that it was a table. I've now gone to Home in the spreadsheet and formatted it as a table :).

Thanks for bringing my attention to this.

Can we go back to my original question: How do I put columns 1, 7 & 8 from a named table into an array?
 
Upvote 0
Exactly the same as in the post you linked you.
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,530
Members
448,969
Latest member
mirek8991

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