View Full Version : Speed up the macro-page layout?

11-10-2010, 01:15 PM

11-10-2010, 04:09 PM
Please give a more detailed outline of the issue. Most people here are far too busy to spend time going through your workbook in an attempt to try and figure out what you are looking for.

Blade Hunter
11-10-2010, 04:34 PM
There is almost 1,000 lines of code there.

To speed this up, here is the biggest one:

Stop doing this


and do this instead


You don't need to select a cell / range to manipulate it.

Look at how much you can save by doing this:

Range(Selection, "R1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False


Sheets("SuitcaseTotal").Range("R1:R" & Range("R" & Rows.Count).End(xlUp).Row).Copy
Sheets(SCACValue).Range("D6").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

Have a go at removing as many select statements as you can and post back. I can guarantee if you make an effort to do this people will be more inclined to help you out but 1,000 lines of recorded code is not something we have the time to read.

Also a lot of that code is redundant, check out your with statements towards the end of the code which is doing the borders, Excel records EVERY setting for the borders when you don't need all of it. Try deleting some of the lines inside the with statements and see if it still works, you will be surprised how much you can remove.



11-10-2010, 05:35 PM
Also turn off screen updating before and turn it on afterwards

Maybe the same for calcualtion:

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
'long running code

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True


11-11-2010, 07:08 AM
Wow, these are great suggestions. There was a glitch when I posted the original comment and it did not appear with the workbook, so I really appreciate you all taking the time to look through this. Most of what I know about VBA I learned from recording the steps first, so I have no doubt that there is a great deal of redundancy in the code. I'll use these suggestions, though I don't know how soon I can revist this. I'll be sure to post back when I do.

11-11-2010, 02:03 PM
Learn to use variables to refer to sheets, ranges etc. especially where there are multiple references to that object

Dim wsSuit As Worksheet
Dim wsAccru As Worksheet
Dim c As Range

Set wsSuit = Sheets("SuitcaseTotal")
Set wsAccru = Sheets("Accruals")
Set c = wsSuit.Range("Table_Query_from_REQ[[#Headers],[SCAC]]")

Range(c, c.End(xlDown)).Copy
wsAccru.Range("Q1").PasteSpecial Paste:=xlPasteValues