MSGBox based on If Statement

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I currently have a WorkbookBeforeClose routine to run that will prevent
closing a workbook if a cell value = "no". The user wants to be able to have
a message box pop up that will allow them to close if they press "Yes" and
disregard the WorkbookBeforeClose routine or to go to cell U105 as per the
routine listed below. Can anyone help me to accomplish both of these options.
Also, can I use a name range instead of U105?

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Worksheets("DIOU Stats").Range("x2").Value = "no" Then
Application.Goto Worksheets("DIOU Stats").Range("u105")
Cancel = True
End If
End Sub
 
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Msgbox("Close the file?", vbYesNo) = vbNo Then
Application.Goto Worksheets("DIOU Stats").Range("named_range")
Cancel = True
End If
End Sub


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
If Worksheets("DIOU Stats").Range("x2").Value = "no" Then
If MsgBox ("Close Anyhow?",vbyesno,"Options") <> vbNo Then
Application.Goto Worksheets("DIOU Stats").Range("u105")
Cancel = True
End If
End If

program will see the "no" value and then will ask if they wish to close
anyhow, rather than doing previous cancel. But if they say "Yes (close
anyhow)" it will skip the cancelling routine and just close the workbook.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top