Speed of Execution

M

Mike H.

I have noticed that when my code comes to things like this:
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
that it slows WAY DOWN! At the start of the subs I have this:
Application.EnableEvents = False
Application.ScreenUpdating = False
Application.Cursor = xlWait
but it still is very slow. I am in a new workbook that I just added during
the execution. Would I need to execute the enableevents statement on the
newly added wb too or is the statement at time of beginning the calling sub
sufficient? Any ideas?
 
S

Stefi

Try also to toggle
Application .Calculation = xlManual

Application .Calculation = xlAutomatic

Regards,
Stefi

„Mike H.†ezt írta:
 
P

Peter T

All those changes to the selected cells are to formats. None of them trigger
an event or trigger calculation. So, unless your code is changing the
selection, disabling those application settings is unlikely to help, if
anything counter-productive. Same applies to calculation, don't change it
simply for this.

If the selection is extremely large re-formatting all those properties might
take a while, and probably unnecessary.

However, if you are changing the selection in some kind of loop, post the
code.

Regards,
Peter T
 
J

JP

Hello,

I agree with Peter on this one, it looks like recorded code.

1- What are you trying to do with this code? Center some text? If so,
you can delete most of these instructions to make the code compact/
faster.
2- What selection are you acting on? Are you limiting the selection to
only the text you need to manipulate?


Hope this helps,
JP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top