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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Please try this
Range("A1").Value = DateSerial(Year(Now()), Month(Now()), 1)
Range("A1").NumberFormat = "mmmm yyyy"
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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