vba yes vba no 2 different macros

Lauren279

Board Regular
Joined
Aug 19, 2014
Messages
95
hi

i have this code to run when a cell is entered with a number but i would like it to do 2 different macros based on the result of the question

Sub worksheet_change(ByVal target As Range)
Set target = Range("A3")
If target.Value > 2 Then

If MsgBox("Would you like to Print?", vbYesNo + vbQuestion) = vbNo Then Exit Sub
Range("a5").Select
Sheets("Cashout Print").Visible = True
Sheets("Cashout Print").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
IgnorePrintAreas:=False
Sheets("Reporting Form").Visible = False
Sheets("AML-CTF").Select
Range("a3").Select
ActiveCell.FormulaR1C1 = "1"
Range("a5").Select
End If
End Sub


i would like to add if the answer is no
Range("A3").Select
Selection.ClearContents
exit sub

but everytime it comes up with an error

am i mising a step????
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Maybe:

Code:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("A3")) Is Nothing Then Exit Sub

If Range("A3").Value > 2 Then
    If MsgBox("Would you like to Print?", vbYesNo + vbQuestion) = vbNo Then
        Application.EnableEvents = False
        Range("A3").ClearContents
        Application.EnableEvents = True
        Exit Sub
    End If
    
    Range("A5").Select
    With Sheets("Cashout Print")
        .Visible = True
        .PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
    End With
    Sheets("Reporting Form").Visible = False
    Sheets("AML-CTF").Activate
    Application.EnableEvents = False
    Range("A3") = 1
    Application.EnableEvents = True
    Range("A5").Select
End If
 
End Sub
 
Upvote 0
sorry had to fix a few things, the below code now works!! thanks for your help

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("A3")) Is Nothing Then Exit Sub
If Range("A3").Value > 2 Then
If MsgBox("Would you like to Print?", vbYesNo + vbQuestion) = vbNo Then
Application.EnableEvents = False
Range("a3").Select
Selection.ClearContents
Application.EnableEvents = True
Exit Sub
End If

Range("A5").Select
With Sheets("Cashout Print")
.Visible = True
.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
End With
Sheets("Reporting Form").Visible = False
Sheets("AML-CTF").Activate
Application.EnableEvents = False
Range("A3") = 1
Application.EnableEvents = True
Range("A5").Select
End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,203,205
Messages
6,054,140
Members
444,703
Latest member
pinkyar23

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