It should be simple, but I'm a VBA noob. I read a lot of forums and found nothing but code that was too complicated, which I could not decrypt to fit my application.
In Excel 2007, I already have a table. I cannot post the image because I am new to the forum, but the table has 3 columns with headers with names from 1 to 3 and one row of data, as shown below:
Table1 +------+------+-------+ |1 | 2 | 3 | +------+------+-------+ |Alpha |Bravo |Charlie| +------+------+-------+
Using this simple table, the following steps are performed and the text "Alpha" is returned.
Sub works() Dim item As String Sheets("Sheet1").Select item = ActiveSheet.Range("Table1[1]") MsgBox (item) End Sub
But I want to be able to refer to table column headers with a variable. Why this does not work:
Sub doesntwork() Dim item As String Dim i As String i = 1 Sheets("Sheet1").Select item = ActiveSheet.Range("Table1[i]") MsgBox (item) End Sub
This should be the syntax, but I have not been able to sort all the various iterations of the VBA syntax over the last 10 years ...
Please, help! Thanks.
source share