How to use a msgbox

Se7en

New Member
Joined
Jan 21, 2005
Messages
4
hi all

i have made a macro with a msgbox inside, i want it to make a msgbowx with only a "ok" button, the msgbox should only appear if the chosen date is in the future or is todays date.
If that is the case i need it to restart the date selection until the user choses a date in the past

the code below gives me an error and the line with the msgbox code is selected then, :unsure: i dont know what i did wrong there

Private Sub CommandButton2_Click()
Sheets("Teams").Select
Date001:
Range("IV655").Select
frmCalendar.Show ' i found this calendar macro somewhere else, and found it rather usefull
Qwerty = ActiveCell.Value
Range("IV654").Select
ActiveCell.Formula = "=Today()"
Qwerty2 = ActiveCell.Value
If Qwerty - Qwerty2 >= 1 Then
QZX = MsgBox("The chosen date " + Qwerty + " is in the future. Today it is " + Qwerty2 + ", chose another date", vbOKOnly, "DateSelectie", , 1000)
GoTo Date001:
End If

End Sub


please :rolleyes: me with this problem
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
actually - ignore that, I think the problem is that you've got a context number without defining the helpfile - you can't have one without the other

:)
 
Upvote 0
Right - I thinked I've figured it out:
You've got Qwerty and Qwerty2 inserted into the message, but these are dates rather than strings.

I've tried your code but added string-versions of the dates:
Private Sub CommandButton2_Click()
Dim qstring as string, q2string as string

Sheets("Teams").Select
Date001:
Range("IV655").Select
frmCalendar.Show ' i found this calendar macro somewhere else, and found it rather usefull
Qwerty = ActiveCell.Value
qstring=Qwerty
Range("IV654").Select
ActiveCell.Formula = "=Today()"
Qwerty2 = ActiveCell.Value
q2string =Qwerty2
If Qwerty - Qwerty2 >= 1 Then
QZX = MsgBox("The chosen date " + qstring + " is in the future. Today it is " + q2string + ", chose another date", vbOKOnly, "DateSelectie", , 1000)
GoTo Date001:
End If

End Sub
 
Upvote 0
Right - I thinked I've figured it out:
You've got Qwerty and Qwerty2 inserted into the message, but these are dates rather than strings.

I've tried your code but added string-versions of the dates:

Private Sub CommandButton2_Click()

Dim qstring As String, q2string As String

Sheets("Teams").Select
Date001:
Range("A1").Select
frmCalendar.Show ' i found this calendar macro somewhere else, and found it rather usefull
Qwerty = ActiveCell.Value
qstring = Qwerty
Range("A2").Select
ActiveCell.Formula = "=Today()"
Qwerty2 = ActiveCell.Value
q2string = Qwerty2
If Qwerty - Qwerty2 >= 1 Then
QZX = MsgBox("The chosen date " + qstring + " is in the future. Today it is " + q2string + ", chose another date", vbOKOnly, "DateSelectie")
GoTo Date001:
End If

End Sub
 
Upvote 0
Hi,

If you want to assign the value of a user response to a variable then you would use the QZX = approach that you have at the moment. You then evaluate QZX to decide what action to take - for example, did the use choose 'Yes' or 'No'? In these cases the MsgBox statement is enclosed in brackets.

However, you are only using the MsgBox to provide a simple message with an OK button. You do not need to test QZX. So remove the QZX = part and the brackets around the statement.

I would also recommend that you highlight the word MsgBox and press F1 to take you to the Help files. This will give you far more detail, including the various arguments. You may find it easier to include the argument names, like this:
Code:
    MsgBox prompt:="The chosen date " + Qwerty + " is in the future. Today it is " _
        + Qwerty2 + ", chose another date", Buttons:=vbOKOnly, Title:="DateSelectie"


HTH
 
Upvote 0

Forum statistics

Threads
1,214,822
Messages
6,121,765
Members
449,049
Latest member
greyangel23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top