PDA

View Full Version : Assigning variable to table or table name



neilm4247
04-20-2016, 12:45 PM
I am having difficulty assigning a variable to a table or a table name. If I use the code as shown I get an "object required" error on the line in bold. Is a ListObject not an object? If I use tblName instead I get an "Invalid qualifier" error.


Sub TestFillTemplateCopy()


Dim TDate As String
Dim tbl As ListObject
Dim tblName As String


Dim rn As Integer ' row number
TDate = Date
Set tbl = Sheets("Flexpak").ListObjects(1)
tblName = Sheets("Flexpak").ListObjects(1).Name
rn = 2
'While Not IsEmpty(Sheets("Flexpak").Range(Cells(rn, 1))
Sheets("TemplateSheet").Copy Before:=Sheets(4)
With ActiveSheet
.Range("C1").Value = Date
.Range("B14").Value = [tbl].Cells(rn, [tbl[Part.]].Column)
End With
'Wend
End Sub

Any help is appreciated.

PAB
04-20-2016, 12:54 PM
Unfortunately there isn't a bolded line!

I assume it is line...


Set tbl = Sheets("Flexpak").ListObjects(1)

neilm4247
04-20-2016, 01:06 PM
Sorry no. The line that results in the "object required" error is:
.Range("B14").Value = [tbl].Cells(rn, [tbl[Part.]].Column). I am sure the problem is in how I am declaring the variable(the line in your reply) but I don't know how to do it any differently. Thanks