Uppercase date format

rjplante

Well-known Member
Joined
Oct 31, 2008
Messages
574
Office Version
  1. 365
Platform
  1. Windows
I am trying to use VBA to enter the date in a dd-mmm-yyyy format with the month in all caps (05-SEP-2018). I have a merged cell C4:D4 and I have the cell custom formated as dd-mmm-yyyy (easy), but no matter what I try I cannot seam to get the month to display in all caps. I have the code below, but it does not work.

Code:
Sheets("Sheet2").Range("C4:D4").Value = Format(Date, "dd-mmm-yyyy")
UCase (Range("C4").Value)

I have also tried the following:

Code:
UCase (Format(Date, "dd-mmm-yyyy"))

Neither one seems to work. What can be done to make this work?

Thanks for any help or direction.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
You will need to make sure that the format of the cell is Text first. We can do that in the code.
Also, since C4 and D4 are merged, you still only write the value to the first cell in that merge (C4).

So this should do what you want:
Code:
    Range("C4").NumberFormat = "@"
    Range("C4") = UCase(Format(Date, "dd-mmm-yyyy"))
 
Upvote 0
Thanks, that worked great! What does the NumberFormat = "@" do in the code?
 
Upvote 0
What does the NumberFormat = "@" do in the code?
It is the "Text" format. It is the same if you went to that cell, right-clicked, select Format Cells, go to the Number tab and select the "Text" option.

You can get this code by turning on the Macro Recorder, and record yourself performing those steps above manually.
 
Upvote 0
You will need to make sure that the format of the cell is Text first.
If the OP would like the cell to contain a real Excel date, but display it as was requested, he could use this code...
Code:
[table="width: 500"]
[tr]
	[td]With Sheets("Sheet2").Range("C4")
  .Value = Date
  .NumberFormat = "dd-""" & UCase(Format(Date, "mmm")) & """-yyyy"
End With[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0
I like it, except it could get problematic if the cell refers to a another cell with changing values or if we were to copy and paste the formatting on another cell.
 
Upvote 0
I like it, except it could get problematic if the cell refers to a another cell with changing values or if we were to copy and paste the formatting on another cell.
The OP used the Date function in his code which, if truly representative of his needs, means the date will not be dependent on the value in another cell. If it turns out that the date is dependent on another cell's value, I believe we could use my solution (modified for the cell reference) in a Change event procedure rather than a macro (as I think the OP might be looking to use).
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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