Continue or Exit Macro based on cell value

rachel06

Board Regular
Joined
Feb 3, 2016
Messages
126
Office Version
  1. 365
Platform
  1. Windows
Hi!

Trying to write a macro that looks at the value of C1.

If it's blank, I want a message box to pop up with two options: CONTINUE or EXIT. If they click "Continue", I want the macro to roll on to Copyfilefromto. If they click "Exit", I want the macro to stop so C1 can be filled out and the macro can rerun and all will be well.

This is what I've got and it's only giving OK as an option. Is what I want to do even possible?

Code:
Sub CheckQtr()

Dim mycheck As VbMsgBoxResult

If Range("C1").Value = "" Then

    mycheck = MsgBox("No quarter has been indicated in cell C1. Click CONTINUE to proceed or EXIT to return to Excel.  ", vbContinueExit)
    If mycheck = vbExit Then
        Exit Sub
        End If
Else
    Call Copyfilefromto
End If

End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
I'm not sure if the vbContinueExit option exists, in my version it doesn't exist. But if it works in your version it should be like this:

VBA Code:
Sub CheckQtr()
  Dim mycheck As VbMsgBoxResult

  If Range("C1").Value = "" Then
    mycheck = MsgBox("No quarter has been indicated in cell C1. Click CONTINUE to proceed or EXIT to return to Excel.  ", vbContinueExit)
    If mycheck = vbExit Then
        Exit Sub
    End If
  End If
 
  Call Copyfilefromto
End Sub

Or use this:

VBA Code:
Sub CheckQtr()
  Dim mycheck As VbMsgBoxResult
 
  If Range("C1").Value = "" Then
    mycheck = MsgBox("Continue", vbYesNo)
    If mycheck = vbNo Then
      Exit Sub
    End If
  End If
 
  Call Copyfilefromto
End Sub
 
Upvote 1
Solution
I'm not sure if the vbContinueExit option exists, in my version it doesn't exist. But if it works in your version it should be like this:

VBA Code:
Sub CheckQtr()
  Dim mycheck As VbMsgBoxResult

  If Range("C1").Value = "" Then
    mycheck = MsgBox("No quarter has been indicated in cell C1. Click CONTINUE to proceed or EXIT to return to Excel.  ", vbContinueExit)
    If mycheck = vbExit Then
        Exit Sub
    End If
  End If
 
  Call Copyfilefromto
End Sub

Or use this:

VBA Code:
Sub CheckQtr()
  Dim mycheck As VbMsgBoxResult
 
  If Range("C1").Value = "" Then
    mycheck = MsgBox("Continue", vbYesNo)
    If mycheck = vbNo Then
      Exit Sub
    End If
  End If
 
  Call Copyfilefromto
End Sub
Thanks! I'm learning more and more about this stuff and just kind of playing around with it! Thought that the vbYesNo could maybe be modified to whatever you would like the buttons to say. Your solution is super simple and straight forward. Thanks so much!!!

This is actually part of a larger macro that someone who is no longer on my team created that I kind of inherited and I've been making tweaks and adding safeguards.

You all are the best!
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,260
Members
452,627
Latest member
KitkatToby

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