ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Yes or No Box then run macro (https://www.excelbanter.com/excel-programming/389413-yes-no-box-then-run-macro.html)

[email protected]

Yes or No Box then run macro
 
Hi

I have two macros,

I want to run a macro based on whether the user clicks yes to a
question or no to a question,

I do not know how to make this message popup on screen,

Can someone help?

Thanks

Andrea


Jan Karel Pieterse

Yes or No Box then run macro
 
Hi,

I want to run a macro based on whether the user clicks yes to a
question or no to a question,

I do not know how to make this message popup on screen,


Like this:

Sub AskQuestion
If Msgbox("Turn Left?",vbyesNo+vbQuestion)=vbYes Then
TurnLeft
Else
TurnRight
End If
End Sub

Sub TurnLeft()
Msgbox "Going to the left!"
End Sub

Sub TurnRight()
Msgbox "Going to the right!"
End Sub

Regards,

Jan Karel Pieterse
Excel MVP
http://www.jkp-ads.com
Member of:
Professional Office Developer Association
www.proofficedev.com


Mike H

Yes or No Box then run macro
 
One way is to paste this into a module and put a button on your worksheet to
call it:-

Sub answerme()
msg = "Answer YES or NO"
response = MsgBox(msg, vbYesNo)
If response = vbYes Then
MsgBox ("You clicked YES")
'Run the yes macro
Else
MsgBox ("You clicked NO")
'Run the no macro
End If
End Sub

Mike

" wrote:

Hi

I have two macros,

I want to run a macro based on whether the user clicks yes to a
question or no to a question,

I do not know how to make this message popup on screen,

Can someone help?

Thanks

Andrea



[email protected]

Yes or No Box then run macro
 
Hi

Thanks for the response,

The first option was what I needed as the macro works with multiple
files. Only one problem so far,

When my macro is looping through the questions the window does not
refresh so the question windows appears behind the other one when it
has been clicked.....Where can I add a window refresh so the box
disappears when the question has been answered,

Many thanks,

Andrea

On May 15, 11:17 am, Mike H wrote:
One way is to paste this into a module and put a button on your worksheet to
call it:-

Sub answerme()
msg = "Answer YES or NO"
response = MsgBox(msg, vbYesNo)
If response = vbYes Then
MsgBox ("You clicked YES")
'Run the yes macro
Else
MsgBox ("You clicked NO")
'Run the no macro
End If
End Sub

Mike



" wrote:
Hi


I have two macros,


I want to run a macro based on whether the user clicks yes to a
question or no to a question,


I do not know how to make this message popup on screen,


Can someone help?


Thanks


Andrea- Hide quoted text -


- Show quoted text -




Mike

Yes or No Box then run macro
 
Sub MyQuestion()
If MsgBox("Yes or No?", vbYesNo + vbQuestion) < vbYes Then
MsgBox "No Macro"
Else
MsgBox "Yes Macro"
End If
End Sub

" wrote:

Hi

I have two macros,

I want to run a macro based on whether the user clicks yes to a
question or no to a question,

I do not know how to make this message popup on screen,

Can someone help?

Thanks

Andrea



[email protected]

Yes or No Box then run macro
 
Hi

This does not answer my previous question about the updating of the
questions to refresh the screen,

Can someone else help?

Andrea

On May 15, 11:58 am, Mike wrote:
Sub MyQuestion()
If MsgBox("Yes or No?", vbYesNo + vbQuestion) < vbYes Then
MsgBox "No Macro"
Else
MsgBox "Yes Macro"
End If
End Sub



" wrote:
Hi


I have two macros,


I want to run a macro based on whether the user clicks yes to a
question or no to a question,


I do not know how to make this message popup on screen,


Can someone help?


Thanks


Andrea- Hide quoted text -


- Show quoted text -




Dave Peterson

Yes or No Box then run macro
 
Application.screenupdating = true
will refresh the screen.

Turn it back to false when you want to hide the flickering.

wrote:

Hi

Thanks for the response,

The first option was what I needed as the macro works with multiple
files. Only one problem so far,

When my macro is looping through the questions the window does not
refresh so the question windows appears behind the other one when it
has been clicked.....Where can I add a window refresh so the box
disappears when the question has been answered,

Many thanks,

Andrea

On May 15, 11:17 am, Mike H wrote:
One way is to paste this into a module and put a button on your worksheet to
call it:-

Sub answerme()
msg = "Answer YES or NO"
response = MsgBox(msg, vbYesNo)
If response = vbYes Then
MsgBox ("You clicked YES")
'Run the yes macro
Else
MsgBox ("You clicked NO")
'Run the no macro
End If
End Sub

Mike



" wrote:
Hi


I have two macros,


I want to run a macro based on whether the user clicks yes to a
question or no to a question,


I do not know how to make this message popup on screen,


Can someone help?


Thanks


Andrea- Hide quoted text -


- Show quoted text -


--

Dave Peterson

Dave Peterson

Yes or No Box then run macro
 
Like:

application.screenupdating = true
resp = msgbox...
application.screenupdating = false

wrote:

Hi

Thanks for the response,

The first option was what I needed as the macro works with multiple
files. Only one problem so far,

When my macro is looping through the questions the window does not
refresh so the question windows appears behind the other one when it
has been clicked.....Where can I add a window refresh so the box
disappears when the question has been answered,

Many thanks,

Andrea

On May 15, 11:17 am, Mike H wrote:
One way is to paste this into a module and put a button on your worksheet to
call it:-

Sub answerme()
msg = "Answer YES or NO"
response = MsgBox(msg, vbYesNo)
If response = vbYes Then
MsgBox ("You clicked YES")
'Run the yes macro
Else
MsgBox ("You clicked NO")
'Run the no macro
End If
End Sub

Mike



" wrote:
Hi


I have two macros,


I want to run a macro based on whether the user clicks yes to a
question or no to a question,


I do not know how to make this message popup on screen,


Can someone help?


Thanks


Andrea- Hide quoted text -


- Show quoted text -


--

Dave Peterson


All times are GMT +1. The time now is 05:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com