Yes or no msg box

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

Guest

please help how can I assign macro in msgbox that if he click yes to go
sheet1 if he click no to stay on active sheet

Thanks
 
If MsgBox("Goto Sheet1?",vbYesNo) = vbYes Then
Worksheets("Sheet1").Activate
End If

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
Option Explicit
sub Test()
dim resp as long

resp = msgbox(Prompt:="Go to Sheet1", buttons:=vbyesno)

if resp = vbyes then
worksheets("sheet1").select
end if
end sub
 
worksheets(1) for first sheet
worksheets("sheet1") for named sheet
vbYesCancel might be used instead

Sub stay_OR_Sheet1()
MsgBox "Do you want to go sheet1", vbYesNo
On Error Resume Next
If vbYes Then Worksheets("sheet4").Activate
If Err.Number = 9 Then
MsgBox "Sorry but sheet4 no longer exits, so staying here anyway"
End
On Error GoTo 0
Rem rest of code
End Sub

For more information see HELP while within the VBA editor, and perhaps
http://www.mvps.org/dmcritchie/excel/inputbox.htm
 
Sorry about not changing code after testing
they should all show sheet1

If vbYes Then Worksheets("sheet1").Activate
 
Back
Top