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
 

Some videos you may like

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Tom Urtis

MrExcel MVP
Joined
Feb 10, 2002
Messages
11,225
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
 

Watch MrExcel Video

Forum statistics

Threads
1,123,323
Messages
5,600,954
Members
414,417
Latest member
Nobu

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