Slow running Workbook Open macros

si_1970

New Member
Joined
Aug 26, 2013
Messages
13
Hi All

I have inherited a workbook to sort out which with my limited knowledge of Excel is causing me a bit of a headache. Upon opening the workbook updates a list of names from an external source (another workbook) and then asks for the user to enter their payroll number which it validates against the list. The rest of the workbook appears pretty straight forward and i have sorted the majority of issues, but for some reason there are so many checks to go through when opening the workbook.

I have got everything running however I am still stuck with a spinning wheel for 20 - 30 seconds before the input box appears.

Any help that you can give to simplify the below will be appreciated.

Code:
Private Sub Workbook_Open()
    Application.ScreenUpdating = False
    Dim myValue As Variant
    Worksheets("engineers").Activate
    Range("A3").Select
    'Updates list of names from an external source
    Selection.ListObject.TableObject.Refresh
    On Error GoTo Procend


    'If sheet already contains data k22 will be greater than 1 and no macros are to run
    If Sheets("Header").Range("k22").Value >= 1 Then
        Sheets("Header").Protect "Password1"    'for some reason the header sheet always opens unprotected
        Sheets("Header").Select
        Range("c11").Select
        ActiveWindow.ScrollRow = 1
        ActiveWindow.ScrollColumn = 1
        GoTo Procend


    Else
        'If sheet1 is visible no macros will run. Sheet one contains folder link information populated at first use and used in later macros.
        If Sheets("Sheet1").Visible = True Then
            Sheets("Sheet1").Select
            GoTo Procend


        Else
            'An input box is enabled for the user of the workbook to enter their payroll number. If nothing is entered then the workbook closes
            myValue = InputBox("ADVISORS - Enter your Payroll Number" & vbNewLine & vbNewLine & "CAUTION - ZERO INPUT OR PRESSING CANCEL WILL CLOSE THE TOOL", "PAYROLL NUMBER VERIFICATION")
            If myValue = vbNullString Then
                MsgBox "The tool will now close", vbCritical, "YOU WERE WARNED"
                'macro to clear all user fields of data
                Run "startclear"
                Application.DisplayAlerts = False
                ThisWorkbook.Close


            Else
                'if the user enters a payroll number which is not found then a userform runs to allow data capture and then the main macro runs
                Sheets("List Data").Range("A1").Value = myValue
                If Sheets("List Data").Range("a3").Value = 0 Then
                    UserForm1.Show
                    Run "EngCheck"


                Else
                    'if the user enters a valid payroll number the main macro runs
                    Run "EngCheck"
                End If
            End If
        End If
    End If
    Application.ScreenUpdating = True
Procend:     Exit Sub


End Sub
 
Last edited by a moderator:

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
consider
If Sheets("Header").Range("k22").Value >= 1 Then ExitSub as the first check if you really want no macros to run
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top