I’m using VBA to populate an Excel “table” range from a subset of other data.
Getting the data is fast (either from a cached array or from a SQL query on data in another sheet), but the adding and deleting is SLOW.
With Worksheets("Overview").ListObjects("OverviewServiceTable")
For i = .ListRows.Count To 1 Step -1
.ListRows(i).Delete
Next
For i = 0 To UBound(cache)
Set NewRow = .ListRows.Add(AlwaysInsert:=True)
NewRow.Range.Cells(1, 1).Value = cache(i)
Next
End With
Using a bit of basic profiling, it’s taking up to a second per row to both add and delete rows. Is there a much faster way of clearing and updating a table like this? Otherwise I’ll resort to using “plain” cell ranges formatted to look pretty, but then nice things like the Autofilters etc will go away.
Thanks.
You could try setting calculation to manual and turn off screen updating while the code runs