Results 1 to 3 of 3

Speed Up Macro / VBA

Threaded View

  1. #1
    Registered User
    Join Date
    03-25-2012
    Location
    England
    MS-Off Ver
    Excel 2007 & Excel 2011 for Mac
    Posts
    79

    Speed Up Macro / VBA

    Hi,

    I have the following VBA code/Macro which is attached to a button on a user form which does the following:

    1) Checks which version of Excel a PC is running then if it is using XL2007 + performs the code or else advises how to procede
    2) Once checked it then checks a cell on a specific sheet and depending on the value hides cells and adjust page breaks
    3) It then prints to PDf

    The problem is its so very slow and just wonderd if there was a way of speeding it up a bit

    Many Thanks

    Private Sub CommandButton1_Click()
    
    Application.DisplayAlerts = False
    Application.ScreenUpdating = False
    
    Dim r As Integer
    Dim k As Integer
    Dim Evers As Long
    Dim Mailbox As String
    Dim rRng As Excel.Range
    
    ' Get Excel Version
    
        If Val(Application.Version) < 12 Then
         Evers = 11
            'You use Excel 97-2003
        Else
         Evers = 12
            'You use Excel 2007 or higher
        End If
        
        Sheets("Report").Visible = True
        Sheets("Report").Select
        Range("D9").Select
        Cells.CheckSpelling SpellLang:=2057
        
    
    'Clear all existing page breaks
        
        Sheets("Report").ResetAllPageBreaks
    
        
    Select Case Sheets("Unit").Range("C1").Value
        
    Case Is = "Capcon"
     
         For r = 70 To 50 Step -1
           Sheets("Report").Rows(r).EntireRow.Hidden = True
        Next r
        For r = 43 To 23 Step -1
           Sheets("Report").Rows(r).EntireRow.Hidden = True
        Next r
        
        'set page breaks
        
        Sheets("Report").HPageBreaks.Add before:=Cells(102, 1)
        Sheets("Report").HPageBreaks.Add before:=Cells(149, 1)
        
        
        
     Case Is = "Controller", Is = "Mini Controller"
     
        For r = 43 To 23 Step -1
          k = Len(Sheets("Report").Cells(r, 7)) + Len(Sheets("Report").Cells(r, 8)) + Len(Sheets("Report").Cells(r, 9)) + Len(Sheets("Report").Cells(r, 10))
          Sheets("Report").Rows(r).EntireRow.Hidden = (k = 0)
       
        Next r
        
          
        For r = 70 To 50 Step -1
            k = Len(Sheets("Report").Cells(r, 7)) + Len(Sheets("Report").Cells(r, 8)) + Len(Sheets("Report").Cells(r, 9)) + Len(Sheets("Report").Cells(r, 10))
            Sheets("Report").Rows(r).EntireRow.Hidden = (k = 0)
        Next r
        
        'set page breaks
        
        Sheets("Report").HPageBreaks.Add before:=Cells(78, 1)
        Sheets("Report").HPageBreaks.Add before:=Cells(149, 1)
        
    End Select
    
    
    If Evers = 12 Then
        Mailbox = ActiveWorkbook.Path
        Sheets("Report").Visible = True
        Sheets("Report").Select
            ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
            Mailbox & "\" & "Headline.pdf", Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
            True
        
        Sheets("Report").Visible = False
    Else
    ' We are on Version 2003 or lower...
    MsgBox "You are using a version of Excel which is 2003 or lower. You will therefore need to manually print the report to a pdf file called Headline.pdf and save this in the mailbox folder that the stock is saved in", vbOKOnly, "Capcon Headline Report"
    Sheets("Report").Visible = True
    Sheets("Report").Select
    End If
    
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    
    End Sub
    Last edited by zhb12810; 07-23-2012 at 06:54 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1