Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MsgBox Response Problem 1

Status
Not open for further replies.

Harlequin007

Technical User
Feb 9, 2004
249
GB
Morning Everyone

I have an Excel workbook and one of the worksheets gives the user a button which when pressed should display a dialog box prompting them to ensure they have correctly located their cursor. If they select Yes - it should execute the code to insert a group of pre-formatted cells. If No, just exit the sub.

Here's what I have:

Dim Response As Integer
MsgBox ("Have You Selected a Cell in Column A and below Row 77"), vbYesNo, ("DVW Workbook")
If Response = vbYes Then
GoTo Insert_Header
Else
MsgBox ("Please Place Your Cursor In Column 'A' and Continue"), vbOKOnly, ("DVW Workbook")
GoTo Bottom
End If

Insert_Header:
My code goes here

Problem:

Whether I select "Yes" or "No" the code exits.

Bottom:
End Sub

I'm confused and wiery - been trying to sort this all morning. I know it's something simple I am overlooking but 2 heads are better than 1.


----------------------------
Cogito Ergo Sum [jester2]
----------------------------
 
Try this

Code:
Response = msgbbox("Blah de Blah", vbYesNo,"blah de blah")
if Response = vbyes then

else

end if

Deleco
 
Hi!

Try assigning the result of the msgbox to the variable Response.

[tt]Response = MsgBox ("Have You Selected a Cell in Column A and below Row 77", vbYesNo, "DVW Workbook")[/tt]

Roy-Vidar
 
you need to assign the yes or no that the message box creates to something by putting brackets round the parameters eg

Response = MsgBox (("Have You Selected a Cell in Column A and below Row 77"), vbYesNo, ("DVW Workbook"))

then your if statement should work
 
Adrian

Thanks firstly for the prompt response and also all of you for pointing out what should have been obvious - tying the response to the message box result code.

[colorface] Thanks [colorface]

This is what I ended up with:

Response = MsgBox(("Have You Selected a Cell in Column A and below Row 77"), vbYesNo, ("DVW Workbook"))
If Response = vbYes Then
GoTo Insert_Header
Else
MsgBox ("Please Place Your Cursor In Column 'A' and Continue"), vbOKOnly, ("DVW Workbook")
GoTo Bottom
End If

----------------------------
Cogito Ergo Sum [jester2]
----------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top