Hello Everyone,
Can anyone suggest a clean way of updating an excel table from an array that includes new column headings?
I've got a macro that outputs an array of column headings and values to a spreadsheet, and then formats the output as a table.
When updating the information using the macro, I'd like to preserve the same table (so that my spreadsheet formulas stay intact).
The problem is that when I dump the array values into the table range, the table gets deleted.
Any solutions I've found are pretty ugly.
The code goes like this:
Can anyone suggest a clean way of updating an excel table from an array that includes new column headings?
I've got a macro that outputs an array of column headings and values to a spreadsheet, and then formats the output as a table.
When updating the information using the macro, I'd like to preserve the same table (so that my spreadsheet formulas stay intact).
The problem is that when I dump the array values into the table range, the table gets deleted.
Any solutions I've found are pretty ugly.
The code goes like this:
Code:
[COLOR=#333333]
[/COLOR]'Grab the table if it already exists
For each objTable in MySheet.ListObjects
If objTable.Name = "MyTable" then
Set MyTable = MyRange
Exit For
End if
Next
'If the table does not exist, create it
If MyTable is Nothing then
Set MyTable = MySheet.ListObjects.Add(xlSrcRange, MyRange, , xlYes)
MyTable.Name = "MyTable"
End If
' Perform the data dump
[COLOR=#333333]MyRange.Value2 = Application.Transpose(arrValues)
[/COLOR]