Make this code more efficient

HWL

Active Member
Joined
Dec 1, 2009
Messages
462
I have a macro that works fine except this piece of it which dramatically slows down. The spread sheet it is applying to has about 3000 rows of data.

This piece of code is simply trying to format the sheet; set freeze panes, make font consistent, autofit rows/cols, and delete blank rows. Is there someone who could re-write it to dramatically increase the speed? THANKS

Application.StatusBar = "****Please Wait***** Formatting " & Sheets(1).Name
Sheets(1).Activate
Rows("2:2").Select
ActiveWindow.FreezePanes = True
Cells.Select
With Selection.Font
.Name = "Arial"
.Size = 12
Cells.EntireColumn.AutoFit
Cells.EntireRow.AutoFit
End With
'deletes blank rows
Dim LastRow1 As Long, i As Long
LastRow1 = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
For i = LastRow1 To 1 Step -1 'row 1 is the header row.
With Rows(i)
If Application.WorksheetFunction.CountBlank(.Cells) = .Cells.Count Then .EntireRow.Delete
End With
Next i
'end blank row code
 
Investigate whether this:

With .Cells.Font

targets only the usedrange of the sheet, or the full sheet.

What is the usedrange of that sheet, by the way?

Hmm, I picked up the usedrange code somewhere else, it is supposed to tell me the last populated row so that the loop only cycles to there instead of arbitrarily putting some high number like 50000, but maybe its not working either
 
Upvote 0

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Sorry, that should be

Code:
With [COLOR=red]UsedRange[/COLOR].Cells.Font
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,710
Members
452,939
Latest member
WCrawford

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