display month name in msgbox

rjwebgraphix

Well-known Member
Joined
May 25, 2010
Messages
590
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

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
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.")
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,217,674
Messages
6,137,923
Members
450,098
Latest member
Ikmal Sabri

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