VBA IF statement - Pls help

NewUser2

Board Regular
Joined
Jan 27, 2015
Messages
54
Hi, so I am new to VBA, as you can tell from the name!

I have some code, that others wrote, that I need to change. The way it works is a user presses a button to run reports (On Sheet1), then a message box pops up and says "are you sure you want to run all reports?". I can not change this part of it.\

My task, I am writing something so these reports are started in the morning through task scheduler so that they are already done by the time I get in in the morning. (that part is no problem). This is done by using a blank workbook that upon open, calls the code that runs all the reports (lets call this Sheet2).

Where I am getting stuck... you guessed it! At the pop-up message.

Is there some way to change the code in Sheet1 so that:
IF Sheet2 = Open.Skip message box
Else = Display message box
Resume as normal

Thank you!
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
First, you should make sure you are comfortable with the editor for VBA in Excel. Check out this link: Section 1: Programming in Excel (Macros)

Sheet manipulation is fairly easy once you get the hang of the environment. The sheets are objects that have different values associated with them, so you could so something like

Code:
Option Explicit
Sub tester()
Dim answer As Long


If ActiveSheet.Name <> "Sheet2" Then
    answer = MsgBox("Are you sure you want to run all reports?", vbYesNo)
    
    If answer = vbNo Then
        MsgBox "I will not run."
        Exit Sub
    End If
End If


MsgBox "Running all reports!"




End Sub
 
Upvote 0

Forum statistics

Threads
1,216,115
Messages
6,128,915
Members
449,478
Latest member
Davenil

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