Hi all,
Can someone please clarify the following seeming discrepancy and also how I can achieve the code equivalent to the manual process outlined below?
In the attached workbook, in Sheet1 there is an Excel Table. The formulas within this table are not important; they are simply there to allow testing of calculation times.
If I select a single column within this table and then right-click/Insert Columns/Table Columns to the Left, on my machine Excel takes about 7 seconds to perform the operation. I presume that this is the time to recalculate all formulas since inserting a table column is a volatile action.
If I select a range comprising more than one column, e.g. D1:K1, the same manual operation - which now inserts 8 table columns - does not take 56 seconds (8 columns insertions x 7 seconds each), but rather the same time as for a single column insertion, i.e. 7 seconds.
I have no problem with this! What I would like to achieve, however, is the equivalent via VBA. When I use the macro-recorder on the above operation, I get:
But when I run this macro it does take 56 seconds, i.e. 7 seconds for each column insertion.Please Login or Register to view this content.
What explains the difference? And how can I achieve the equivalent in VBA of my manual operation which took just 7 seconds?
I know that obviously I can add things to the code like Application.Calculation = xlCalculationManual, etc., but that is not my point - in fact, in Manual Calculation mode the relative performance difference is the same: inserting 8 columns manually = 3 seconds, inserting 8 columns via the above code = 24 seconds.
And amending the above so that it loops over a single line of code is obviously only a cosmetic improvement.
Thanks in advance for any assistance.
Regards
Bookmarks