Date Format Issue

jagrenet

Board Regular
Joined
Feb 23, 2022
Messages
81
Office Version
  1. 365
  2. 2013
  3. 2011
  4. 2010
Platform
  1. Windows
Hello Gurus,

I am using the Date function to return Month and Year only to Cell("A1"). When I run the code it returns "Jan-23" to the cell. What I want it to return is "January 2023". While I recognize that this is a Cell Format issue, I have tried to set the Format through Excel and still cannot get it to return as desired. I feel the formatting needs to be done in the code and have designed it in that manner however, I still can't get it to output the text the way I would like it. (Please see my code below)

Dim MyDate, MyYear
Dim MyMonth As String
Dim MyText As String

MyDate = Date
MyYear = Year(MyDate)
MyMonth = MonthName(Month("01/01/2018"))

MyText = MyMonth & " " & MyYear

Range("A1") = MyText

Debug.Print MyText

The Immediate Window returns perfectly, as expected ...... "January 2023". Cell "A1" continues to return "Jan-23"
Not sure what I am missing here.

Thanks,
Jeff
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Please try this
Range("A1").Value = DateSerial(Year(Now()), Month(Now()), 1)
Range("A1").NumberFormat = "mmmm yyyy"
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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