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

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Please try this
Range("A1").Value = DateSerial(Year(Now()), Month(Now()), 1)
Range("A1").NumberFormat = "mmmm yyyy"
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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