Creating array of selected columns from named table

Westbury

Board Regular
Joined
Jun 7, 2009
Messages
129
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
129
Thank you; that works for me and will be useful in other parts of my spreadsheet.
 

Some videos you may like

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Westbury

Board Regular
Joined
Jun 7, 2009
Messages
129
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,589
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,589
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,119,060
Messages
5,575,862
Members
412,688
Latest member
KYLE1788
Top