LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Update "centerheader" code running slowly need help speeding up

I recently added 1 new line of code to the following code I have been
running for a year. Previous to adding the the line of code
"PageSetup.CenterHeader = Range("A1").Value" I would click on a sheet
and there would be a slight almost unnoticable pause while the code
executed. After adding the above code there is now a 5 to 8 second
pause after clicking on the sheet. This pause is the same whether Calc
is on or off.

Is it just the nature of that new line of code or is there a way of
tweaking my code so it executes faster. I have 32 sheets with the same
code for each sheet. The entire Excel 2007 spreadsheet is 7MB
compress. It it was saved in Excel 2003 the file size would approach
20MB so it is a very large file.

What I'm trying to achieve is to make sure that the "crosses at" value
on 9 different charts is updated with the most current value that is
on the same sheet. This is the part that is working fine. I wanted to
update each of the sheets Header with data that is entered in another
location also. That is the additional code that causing the 5-8 second
delay. I also tried code that would update the header of every sheet
after the desired text is entered on a sheet but that code took 5-10
minuted to run so I tried the individual sheet approach hoping that
would run faster.


Private Sub worksheet_activate()
Application.ScreenUpdating = False

'In case sheets are grouped
Sheet4.Select

On Error GoTo Ungroup

'To Unprotect this sheet if protected
If Me.ProtectContents = True Then
ActiveSheet.Select
ActiveSheet.Unprotect
Else
End If

'This updates the sheet print header
PageSetup.CenterHeader = Range("A1").Value <======== This is the
new line of code that slows everything down

'To Update the Charts CrossesAt value from setup sheet that are on
the sheet
With ActiveSheet
If .ChartObjects("Chart 1").Chart.Axes(xlValue).CrossesAt
< .Range("J20") Then
.ChartObjects("Chart 1").Chart.Axes(xlValue).CrossesAt
= .Range("J20")
End If
If .ChartObjects("Chart 2").Chart.Axes(xlValue).CrossesAt
< .Range("K20") Then
.ChartObjects("Chart 2").Chart.Axes(xlValue).CrossesAt
= .Range("K20")
End If
If .ChartObjects("Chart 3").Chart.Axes(xlValue).CrossesAt
< .Range("L20") Then
.ChartObjects("Chart 3").Chart.Axes(xlValue).CrossesAt
= .Range("L20")
End If
If .ChartObjects("Chart 4").Chart.Axes(xlValue).CrossesAt
< .Range("Q20") Then
.ChartObjects("Chart 4").Chart.Axes(xlValue).CrossesAt
= .Range("Q20")
End If
If .ChartObjects("Chart 5").Chart.Axes(xlValue).CrossesAt
< .Range("R20") Then
.ChartObjects("Chart 5").Chart.Axes(xlValue).CrossesAt
= .Range("R20")
End If
If .ChartObjects("Chart 6").Chart.Axes(xlValue).CrossesAt
< .Range("S20") Then
.ChartObjects("Chart 6").Chart.Axes(xlValue).CrossesAt
= .Range("S20")
End If
If .ChartObjects("Chart 7").Chart.Axes(xlValue).CrossesAt
< .Range("T20") Then
.ChartObjects("Chart 7").Chart.Axes(xlValue).CrossesAt
= .Range("T20")
End If
If .ChartObjects("Chart 8").Chart.Axes(xlValue).CrossesAt
< .Range("AA65") Then
.ChartObjects("Chart 8").Chart.Axes(xlValue).CrossesAt
= .Range("AA65")
End If
If .ChartObjects("Chart 9").Chart.Axes(xlValue).CrossesAt
< .Range("AB65") Then
.ChartObjects("Chart 9").Chart.Axes(xlValue).CrossesAt
= .Range("AB65")
End If
End With

Range("AI1:AI262").AutoFilter Field:=1, Criteria1:="<0"

If Me.ProtectContents = False Then
ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True, AllowFormattingColumns:=True, AllowFiltering:=True
'MsgBox "Protected"
Else
ActiveSheet.Unprotect
'MsgBox "Un Protected"
End If
'Also see below
'Me.ProtectDrawingObjects

On Error GoTo 0

'The macro is done. Use Exit sub, otherwise the macro
'execution WILL continue into the error handler
Exit Sub

Ungroup:
MsgBox "Please ungroup sheets"


End Sub



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
"CELL("FILENAME") NOT UPDATE AFTER "SAVE AS" ACTION yossie6 Excel Discussion (Misc queries) 1 June 16th 08 12:16 PM
Running "String" of Code Hokievandal Excel Programming 4 September 5th 07 10:56 AM
Running Custom Code if "Entire Workbook" is Selected for Printing rfedge Excel Programming 1 September 10th 06 06:12 AM
Stop code from running when I click "Cancel" Dean[_9_] Excel Programming 3 March 2nd 06 12:34 AM
"Casing" the strings for smooth code running Hari[_3_] Excel Programming 2 June 16th 04 04:41 PM


All times are GMT +1. The time now is 06:21 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"