Hi guys,

Have a question. trying to get VBA to create a table dynamically, as rows and columns may change in my data. Code I am trying: (Sheet_Anayser1_RS3_QC2 is sheet coded name)

Sub TableFormatting_A1_QC2()

lrow = Sheet_Anayser1_RS3_QC2.Range("A" & Rows.Count).End(xlUp).Row
lcol = Sheet_Anayser1_RS3_QC2.Cells(1, Columns.Count).End(xlToLeft).column


Sheet_Anayser1_RS3_QC2.ListObjects.Add(xlSrcRange, Range(Cells(1, 1), Cells(lrow, lcol)), , xlYes).Name = _
"Tbl2"

However, this only works if Sheet_Anayser1_RS3_QC2 sheet is the active sheet. Also gives run time error 1004 if I run this code and I'm not on the specified sheet.

So the only way I can get this to work is to incorperate: Sheet_Anayser1_RS3_QC2.select

Is there another way or what am I doing wrong? Please help!