Selection.Columns.AutoFit in VBA S-L-O-W

bbhgroup

Board Regular
Joined
Dec 30, 2008
Messages
97
I have a modest size spreadsheet - about 1000 rows and 200 columns

I do a range select :
Code:
ActiveSheet.Range(Cells(5,2), Cells(1000, 200)).Select

'Then:
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
(capture current time)
Selection.Columns.AutoFit
(capture current time)
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

The time difference between the two snapshots is on the order of 30 seconds give or take. During that time Excel has about 50% of total CPU. You can see I've tried to cut down any other activity.

Several of these columns have conditional format equations associated with them, they turn the values colors depending on conditions. Perhaps they are being evaluated?


Is there better way to do this?

This seems completely out of whack. This is a complex spreadsheet, could the autofit function be triggering some other event that is running?
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
try something like this. Dont use ActiveSheet.Range(Cells(5,2), Cells(1000, 200)).Select statement.

Code:
dim Rng as Range
Rng = ActiveSheet.Range("B5:GR1000")
.....
Rng.Columns.Autofit
.....
 
Last edited:
Upvote 0
Can't you just do:

Code:
Columns("B:GR").AutoFit

without using select or even defining the range? I think you can...
 
Upvote 0

Forum statistics

Threads
1,213,551
Messages
6,114,272
Members
448,558
Latest member
aivin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top