conditional message box

S

SFConklin1

Hi There,

I'm trying to create a conditinal message box on open of an Excel spreadsheet.


I would like it to do something like: "Do you want to update the date ranges?
", If yes then a message box to enter the ranges, if no, then another message
box to say "Do you want to enter new time", if yes then a message box to
enter times, if no then end.

Thanks!
 
S

Simon Lloyd

We need much more to go on than that or your worksheet code would be:

Code:
--------------------
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Ans As String, Ans1 As String
If MsgBox("Do you want to update ranges?", vbYesNo, "Range Update?") = vbYes Then
Ans = Application.InputBox("Enter range in this fashion xx:xx", "Range Entry")
Else
If MsgBox("Do you want to enter times?", vbYesNo, "New Times") = vbYes Then
Ans1 = Application.InputBox("Enter new time in this fashion xx:xx", "Time Entry")
End If
End If
If Ans <> "" Then
MsgBox "the range" & Chr(34) & Ans & Chr(34)
End If
If Ans1 <> "" Then
MsgBox "the time" & Chr(34) & Ans1 & Chr(34)
End If
End Sub
--------------------


SFConklin1;385826 said:
Hi There,

I'm trying to create a conditinal message box on open of an Excel
spreadsheet.


I would like it to do something like: "Do you want to update the date
ranges?
", If yes then a message box to enter the ranges, if no, then another
message
box to say "Do you want to enter new time", if yes then a message box
to
enter times, if no then end.

Thanks!


--
Simon Lloyd

Regards,
Simon Lloyd
'The Code Cage' (http://www.thecodecage.com)
 
E

EricG

Open the Visual Basic editor. Double-click on the "ThisWorkbook" object.
Paste in the following code (be careful with line wrap). You will have to
change it to suit your needs, but it gives you the idea.

HTH,

Eric

Private Sub Workbook_Open()
Dim theAns As VbMsgBoxResult
Dim newDates As String
Dim newTimes As String
'
theAns = MsgBox("Do you want to update the Date Ranges?", _
vbQuestion + vbYesNo, "Update Date Ranges?")
Select Case theAns
Case vbYes ' Enter a new date range
newDates = InputBox("Enter new date range (mm/dd/yyyy-mm/dd/yyyy)",
"Enter New Date Range")
Case vbNo ' Ask user to enter new time range
theAns = MsgBox("Do you want to enter New Times?", _
vbQuestion + vbYesNo, "Enter New Times?")
Select Case theAns
Case vbYes ' Enter new time range
newTimes = InputBox("Enter new date range (hh:mm-hh:mm)", "Enter
New Time Range")
Case vbNo
' Do something else or nothing...
End Select ' Enter new times?
End Select ' Update date ranges?
End Sub
 

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

Top