ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Problem with message box return value (https://www.excelbanter.com/excel-programming/303121-problem-message-box-return-value.html)

John Baker

Problem with message box return value
 
Hi:

I am dong something wrong, and don't know what it is. For some reason I am not detecting
the results of button presses with the following code. Can someone show me what I am doing
wrong please? OOPS is a tag I am going to further down in the macro.

Help much appreciated
sub macro()

Dim msgprompt As String
Dim msgbuttons As Integer, msgResults As Integer
msgprompt = "If you are not certain about installing the new spreadsheet click NO in the
area below." & "If you wish to proceed with installation, click YES"
msgbuttons = vbYesNo
MsgTitle = "Confirm Installation"
MsgResult = Msgbox(msgprompt, msgbuttons, MsgTitle)
Select Case msgResults
Case vbYes
GoTo oops
End Select
Range("aa1").Select
ActiveCell() = "No"
Range("a1").Select
Application.ScreenUpdating = False
and so on

to oops:




Thanks

John Baker



Jim Cone

Problem with message box return value
 
John,

If you put "Option Explicit" at the top of your module, it will flag
misspelled variables... msgResults vs msgResult.

Also, I don't believe you want () after ActiveCell.

Regards,
Jim Cone
San Francisco, CA

"John Baker" wrote in message ...
Hi:
I am dong something wrong, and don't know what it is. For some reason I am not detecting
the results of button presses with the following code. Can someone show me what I am doing
wrong please? OOPS is a tag I am going to further down in the macro.
Help much appreciated
sub macro()


Dim msgprompt As String
Dim msgbuttons As Integer, msgResults As Integer
msgprompt = "If you are not certain about installing the new spreadsheet click NO in the
area below." & "If you wish to proceed with installation, click YES"
msgbuttons = vbYesNo
MsgTitle = "Confirm Installation"
MsgResult = Msgbox(msgprompt, msgbuttons, MsgTitle)
Select Case msgResults
Case vbYes
GoTo oops
End Select
Range("aa1").Select
ActiveCell() = "No"
Range("a1").Select
Application.ScreenUpdating = False
and so on


to oops:
Thanks
John Baker


Rob Bovey

Problem with message box return value
 
Hi John,

MsgResult = Msgbox(msgprompt, msgbuttons, MsgTitle)
Select Case msgResults


Unless this is a typo, it looks like a case of the need for Option
Explicit at the top of your code module. You are returning the result from
the message box into an undeclared variable named MsgResult but your
Select...Case statement is looking at a declared variable named msgResults.

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *


"John Baker" wrote in message
...
Hi:

I am dong something wrong, and don't know what it is. For some reason I am

not detecting
the results of button presses with the following code. Can someone show me

what I am doing
wrong please? OOPS is a tag I am going to further down in the macro.

Help much appreciated
sub macro()

Dim msgprompt As String
Dim msgbuttons As Integer, msgResults As Integer
msgprompt = "If you are not certain about installing the new spreadsheet

click NO in the
area below." & "If you wish to proceed with installation, click YES"
msgbuttons = vbYesNo
MsgTitle = "Confirm Installation"
MsgResult = Msgbox(msgprompt, msgbuttons, MsgTitle)
Select Case msgResults
Case vbYes
GoTo oops
End Select
Range("aa1").Select
ActiveCell() = "No"
Range("a1").Select
Application.ScreenUpdating = False
and so on

to oops:




Thanks

John Baker





John Baker

Problem with message box return value
 
Jim:

"Option Explicit" gave me a compile error, but your obsertatioon solved the problem.

Nothing more than a stupid typo!

Thanks a lot

John Baker

"Jim Cone" wrote:

John,

If you put "Option Explicit" at the top of your module, it will flag
misspelled variables... msgResults vs msgResult.

Also, I don't believe you want () after ActiveCell.

Regards,
Jim Cone
San Francisco, CA

"John Baker" wrote in message ...
Hi:
I am dong something wrong, and don't know what it is. For some reason I am not detecting
the results of button presses with the following code. Can someone show me what I am doing
wrong please? OOPS is a tag I am going to further down in the macro.
Help much appreciated
sub macro()


Dim msgprompt As String
Dim msgbuttons As Integer, msgResults As Integer
msgprompt = "If you are not certain about installing the new spreadsheet click NO in the
area below." & "If you wish to proceed with installation, click YES"
msgbuttons = vbYesNo
MsgTitle = "Confirm Installation"
MsgResult = Msgbox(msgprompt, msgbuttons, MsgTitle)
Select Case msgResults
Case vbYes
GoTo oops
End Select
Range("aa1").Select
ActiveCell() = "No"
Range("a1").Select
Application.ScreenUpdating = False
and so on


to oops:
Thanks
John Baker




All times are GMT +1. The time now is 12:37 PM.

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