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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
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,214,614
Messages
6,120,525
Members
448,969
Latest member
mirek8991

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