I've been trying different variation of codes from online research, but none seems to work. The most recent code I tried is as below:
Sub Export_AllStates()
Dim TableArray As Variant
TableArray = Array("StateA[#All]", "StateB[#All]", "StateC[#All]")
For x = LBound(TableArray) To UBound(TableArray)
Set tbl = ThisWorkbook.Worksheets(x).ListObjects(TableArray(x)).Range
tbl.Copy
Workbooks.Add
ActiveSheet.Paste
ActiveWorkbook.SaveAs Filename:="All States.csv"
Next x
End Sub
What I'm trying to accomplish is to combine multiple tables (in this example, three) and have the output copied to a new single table in a new workbook. I have not gotten to the part where I can copy only the column header once, as they are the same for all the tables. Any addition to the code for this requirement would be appreciated too.
I hope I made sense, and I appreciate any feedback I can get.
Thank you.
EDIT: Should have mentioned earlier, the error I get when running this code is "Run-time error '9': Subscript out of range" - referencing the Set tbl line