• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Making a Structured Reference to a Table Column in VBA

PipBoy808

Member
Hello,

I have a table named 'tbtrack' in the worksheet 'shtcodes'. Within this table there is a column with the header 'Tracking Code'.

I'm trying to make a separate range ('DPcodes') on a different sheet equal to the values in this column, so I thought it would be a good idea to set a new range ('TCodes') equal to the column in the table first.

However, I keep getting something wrong. I tried the following:

Code:
Set Tcodes = Evaluate("tbtrack[[#Headers],[Tracking Code]]")
DPcodes.value = Tcodes.value

All this did was make the entire range in 'DPCodes' equal to the actual header rather than the contents of the column. Is there a way to make a structured reference to the range of cells and their values within a column rather than the header?

Much obliged.
 
Couple of things.
First, remove the Headers bit from your code section.
Next, need to make sure that your detination location is the same size. Here's a quick example of copying the Names column from Table1.
Code:
Sub ExampleCode()
Dim myRange As Range
Set myRange = Range("Table1[Names]")
Range("G1").Resize(myRange.Rows.Count, myRange.Columns.Count).Value = myRange.Value
End Sub

Technically, I don't need to figure out how many columns to Resize, as I know that it will be 1. I just put it in there for example purposes.
 
Back
Top