Creating array of selected columns from named table

Westbury

Board Regular
Joined
Jun 7, 2009
Messages
136
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
 

Westbury

Board Regular
Joined
Jun 7, 2009
Messages
136
Thank you; that works for me and will be useful in other parts of my spreadsheet.
 

Some videos you may like

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Westbury

Board Regular
Joined
Jun 7, 2009
Messages
136
For future reference, if the data is simply in a range, not a named Table, how would I copy specific columns into an array?
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,675
Office Version
  1. 2010
Platform
  1. Windows
What do you want... the whole column minus the first row or just the first row?
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,675
Office Version
  1. 2010
Platform
  1. Windows
Hard to give you code without specifics. What is the address of the first header cell?
 

Watch MrExcel Video

Forum statistics

Threads
1,122,241
Messages
5,595,017
Members
413,960
Latest member
ikkin

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
Top