Exceute macro if no error

mhdakhtar8

New Member
Joined
Feb 4, 2013
Messages
36
Hi,

I've a macro which I run to validate if all the required sheets exist in a workbook or not. If no error, I run another macro to do some sets of action.

Requirement: How can I automatically run the second macro based on first? I want to avoid manually running the second macro.

Let me know if you need to see the codes.
 
I did some changes and its working fine for validation but it's not executing the other procedure. I also tried changing the Boolean value but no luck. Please see the code below.

Code:
Sub Generate_Producitvity_Report()
    Dim OW As Workbook, ws As Worksheet, sname As Variant, i As Integer
    Dim sN As Variant, boolFlag As Boolean
    sname = Array("COS REJECT", "APPROVAL SENT", "Pending Client Response", _
        "Awaiting Four-Eye Check", "Awaiting RDS Approval", "SHEET6", "SHEET1")
    Set OW = ActiveWorkbook
    
    boolFlag = True
    For Each sN In sname
        On Error Resume Next
        Set ws = ThisWorkbook.Sheets(sN)
        Debug.Print ws.Name; " found"
        If Err.Number > 0 Then
            Debug.Print sN & "sheet not found"
            Err.Clear
            boolFlag = True
         End If
            If ws.Name = "Sheet6" Or ws.Name = "Sheet1" Then
            Debug.Print "Ranges doesnt matter"
            Else
                 If ws.Range("A1") <> "requestid" Or _
                    ws.Range("B1") <> "Formname" Or _
                    ws.Range("C1") <> "Timestamp" Or _
                    ws.Range("D1") <> "Type" Or _
                    ws.Range("E1") <> "ActionBy" Then
                            Debug.Print "Some Ranges are missing"
                  End If
            End If
        On Error GoTo 0
    Next sN
    If boolFlag = False Then
         MyOtherSub
    End If
End Sub
 
Upvote 0

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
I got it, I had to change the first and last Boolean value to True and middle one to False. Thank you for all your support. I understood the last two Boolean value but may be if you can help me understanding the first one.

Code:
boolFlag = True
 
Upvote 0

Forum statistics

Threads
1,217,402
Messages
6,136,413
Members
450,010
Latest member
Doritto305

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