Dates in MsgBox

maabbot

Board Regular
Joined
May 27, 2002
Messages
56
Hi

I am trying to make a message box that display a given piece of text along with a date. My problem is that the message box never displays the date in A6 when that logival statement is satisfied - it always comes up with the text & 12:00 AM. Can anyone help?

Sub Graph

Dim Y As Date

Y = Range("A6")

If Y = #1/1/03# Then
Text = "Contract signed by IPGJVs for whole term"
ElseIf Y = #12/22/31# Then
Text = "Contract signed by Domgas JVs for whole term"
Else
Text = "Contract assigned by Domgas JVs to IPGJVs on " & Y
End If

MsgBox "" & Text, , "Graph Assumptions"
End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi
Assuming that 'Y' is storing a valid date:<pre>
Text = "Contract assigned by Domgas JVs to IPGJVs on " & Format(Y,"MM/DD/YY")

See the format function in VBA help.

If Y = #01/01/2002# then

Format(Y,"MM/DD/YY")

yields a string: "01/01/2002"

Format(Y,"DDDD, MMMM DD, YYYY")

yields a string:
"Tuesday, January 01, 2002"

ect.......

You are trying to force string concatenation using a value. VB/VBA will
try to resolve this but I would just go ahead and use the correct syntax.

Tom</pre>
This message was edited by TsTom on 2002-10-03 21:45
 
Upvote 0
Tom

Thanks for your reply. After using your tip the format changes such that the date displayed is 30/12/1899 (which isn't the date in range A6. Do you have any further advice?

Many thanks
 
Upvote 0
Yes.
Make sure you have a valid date in A6.
Dim Y as Date not variant

Run this little sub:
<pre>
Sub DateOrNot()

Dim Y As Date

If IsDate(Range("A6").Value) Then
Y = Range("A6").Value
MsgBox "Contract assigned by Domgas JVs to IPGJVs on " & _
Format(Y, "MM/DD/YY"), , "Graph Assumptions"
Else
MsgBox "Invalid Date in cell A6"
End If

End Sub

</pre>
Tom
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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