Use a table name instead of fixed range in a function

BradleyS

Active Member
Joined
Oct 28, 2006
Messages
351
Office Version
  1. 2010
Platform
  1. Windows
I have a table of data in one column called "MyData" and currently set as Worksheets("Data").Range("H39:H49")
The objective is to get the column of data into a comma separated variable

However, I don't seem to be able to find a way to use the table name in my transpose formula below

I'm trying to substitute the range to use a table name, as the table is dynamic, so the range will change

How do I covert this formula (which works fine) to use my table name?
Dim x As Variant
x = Join(Application.WorksheetFunction.Transpose(Worksheets("Data").Range("H39:H49").Value), ",")

as the below doesn't work, and various other methods I have tried to use.
x = Join(Application.WorksheetFunction.Transpose(MyData.Value), ",")
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Hi.

Try this:

Worksheets("Data").ListObjects("Table_Name").ListColumns("MyData")

You need to swap "Table_Name" for the name of your table
 
Upvote 0
x = Join(Application.WorksheetFunction.Transpose(Worksheets("Data").ListObjects(MyData).Value), ",")
Shows error "Script out of range"
 
Upvote 0
x = Join(Application.WorksheetFunction.Transpose(Worksheets("Data").ListObjects(MyData).Value), ",")
Shows error "Script out of range"
I edited my reply to you.
Change that. It should point to the column range
 
Upvote 0
The table and column of data is the same, and still throws an error
x = Join(Application.WorksheetFunction.Transpose(Worksheets("Data").ListObjects("MyData").ListColumns("MyData").Value), ",")
 
Upvote 0
I don't think that you can use the property Value with listcolumns.

Maybe DataBodyRange
 
Upvote 0
Try:
VBA Code:
Sub ConvertData()

    Dim tbl As ListObject
    Dim x As Variant
    
    Set tbl = Range("MyData").ListObject
    x = Join(Application.Transpose(tbl.ListColumns("MyData").DataBodyRange.Value), ",")
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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