display month name in msgbox

rjwebgraphix

Well-known Member
Joined
May 25, 2010
Messages
588
How can I get this to show the name of the month in the msgbox instead of the date? The usage date comes from a cell which is already formatted to display the month name, but is really just a date.

Code:
Sheets("Datasheet").Activate
UsageDate = Sheets("Summary").Cells(4, "A")
With Sheets("Datasheet")
    lrow = 2
    Do While Cells(lrow, "A") <> ""
        DateToChk = Cells(lrow, "O")
        
        If Month(UsageDate) = Month(DateToChk) Then
            GoTo ChkDistrict
        End If
        lrow = lrow + 1
    Loop
    
    Sheets("IMPORTER").Activate
    MsgBox ("There is no data in the file for the month of " & UsageDate & (Chr(13)) & _
            "Either change the date or import a file with data for that month."), vbCritical
    Exit Sub
End With
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Tom Urtis

MrExcel MVP
Joined
Feb 10, 2002
Messages
11,270
In your messagebox code line, change
usagedate

to
Format(usagedate, "mmmm")

example

MsgBox ("There is no data in the file for the month of " & Format(usagedate, "mmmm") & (Chr(13)) & _
"Either change the date or import a file with data for that month.")
 

rjwebgraphix

Well-known Member
Joined
May 25, 2010
Messages
588
Thanks! It was funny, I found another solutions and was just coming in to say I found it. It works, but is different, so here is an alternate solution.

Code:
    MsgBox ("There is no data in the file for the month of " & MonthName(Month(UsageDate)) & (Chr(13)) & _
            "Either change the date or import a file with data for that month."), vbCritical

Found it by accident when I was trying different things. I tried to use monthname as a variable but it error'd because its a built-in function. So I just typed MonthName and pressed F1 and WOW, there's a solution. :)

Thanks again,

RJ
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,384
Messages
5,836,946
Members
430,464
Latest member
nickburrett

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
Top