Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro running slow in Excel

Status
Not open for further replies.

ChristianDK

Programmer
May 31, 2007
18
DK
Thanks to the help on this forum i have made the following:

Sub KlarTilUdskriftAlt()

Sheets("Nøgl").Visible = False

For i = 2 To ActiveWorkbook.Sheets.Count - 5
Set SheetMark = ActiveWorkbook.Sheets(i)
If SheetMark.Visible Then
SheetMark.Range("A1").AutoFilter Field:=1, Criteria1:="="

SheetMark.PageSetup.LeftFooter = "&""Times New Roman,Normal""&9 " & Range("inddata!b3")

ActiveWindow.View = xlPageBreakPreview
Else
End If
Next

Sheets("ForR").PageSetup.LeftFooter = ""

Sheets("Reer").PageSetup.LeftFooter = ""

Sheets("ForS").PageSetup.LeftFooter = ""
End Sub


On the computer I am working on it takes about 3 sec to run it, but on the laptops it takes around 16 sec. Any way to make it go faster? other then buy new laptops :)

Also the "ActiveWindow.View = xlPageBreakPreview" i cant seem to make it work on sheets, ActiveWindow? any way to make it work on at none selected sheet?
i like to use it with my "SheetMark" so all the sheets are effected by the autofilter and shows the pagebreak view(not hidden sheets)

Hope any of you got any good ideér's :)
 




Hi,

Here are a few suggested changes: the FOR...NEXT, the footer sheet reference, the ActiveWindow statement...
Code:
Sub KlarTilUdskriftAlt()
    
    Sheets("Nøgl").Visible = False
        
    For Each SheetMark In Sheets
        With SheetMark
             If .Visible Then
                .Range("A1").AutoFilter Field:=1, Criteria1:="="
            
                .PageSetup.LeftFooter = "&""Times New Roman,Normal""&9 " & Sheets("inddata").Range("b3")
'''This statement does NOTHING for each SheetMark.
'                ActiveWindow.View = xlPageBreakPreview
            End If
        End With
    Next
  
    Sheets("ForR").PageSetup.LeftFooter = ""
    
    Sheets("Reer").PageSetup.LeftFooter = ""
    
    Sheets("ForS").PageSetup.LeftFooter = ""
End Sub

Skip,

[glasses] [red][/red]
[tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top