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
 

Some videos you may like

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
51,044
Office Version
  1. 365
Platform
  1. Windows
Do you actually have a structured table, or just a named range?
 

Westbury

Board Regular
Joined
Jun 7, 2009
Messages
129
the table has a name that appears in Name Manager. Its range is $A$1:$J$4267
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
51,044
Office Version
  1. 365
Platform
  1. Windows
Yes but is it a structured table? If you select that name in the name manager, can you edit it?
 

Westbury

Board Regular
Joined
Jun 7, 2009
Messages
129

ADVERTISEMENT

From Name Manager in the spreadsheet I can edit the name and the range
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
51,044
Office Version
  1. 365
Platform
  1. Windows
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
 

Westbury

Board Regular
Joined
Jun 7, 2009
Messages
129

ADVERTISEMENT

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?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
51,044
Office Version
  1. 365
Platform
  1. Windows
Exactly the same as in the post you linked you.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
51,044
Office Version
  1. 365
Platform
  1. Windows
Did you get it to work?
 

Watch MrExcel Video

Forum statistics

Threads
1,119,065
Messages
5,575,923
Members
412,689
Latest member
nhsmedic
Top