VBA convert date to text

Shadkng

Active Member
Joined
Oct 11, 2018
Messages
370
Hi, in the below snippet of code I need help in revising the code so range ("G15"), which is a date can be changed to text. Currently when we enter the date in that field we do so as 052324 and it changes to appear as 5/23/24. But when the date moves to the outlook email it shows as 52324. I want it to appear as 5/23/24 if possible. Thanks for the help.

VBA Code:
With oMail
        .SentOnBehalfOfName = "sales@rfbcorp.com"
        .To = Worksheets("DETAIL FORM").Range("G3")
        .cc = ""
        .HTMLBody = "See attached order confirmation. Your order will be released for production. Please notify us immediately if any changes are needed." & "<br/>" & "<br/>" _
                   & "Estimated ship date: " & Sheets("FINALORDER").Range("G15") & "<br/>" & "<br/>" _
                   & "Thank You" & "<br/>" & "<br/>" _
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
What happens if you change
VBA Code:
Sheets("FINALORDER").Range("G15")

to

VBA Code:
Format(Sheets("FINALORDER").Range("G15"), "m/dd/yyyy")

If not what is causing the change in the below?
and it changes to appear as 5/23/24.
 
Upvote 0
What happens if you change
VBA Code:
Sheets("FINALORDER").Range("G15")

to

VBA Code:
Format(Sheets("FINALORDER").Range("G15"), "m/dd/yyyy")

If not what is causing the change in the below?
and it changes to appear as 5/23/24.
I got the following weird date

Estimated ship date: 8/10/1964
 
Upvote 0
What in your cell is converting the number 052324 to appear as a date 5/23/24?
 
Upvote 0
Coming at it another way try (but it is dependent on the answer to my previous question)...

Rich (BB code):
Dim Holder As String
Holder = Left(Sheets("FINALORDER").Range("G15"), Len(Sheets("FINALORDER").Range("G15")) - 4) & "/" & Mid(Sheets("FINALORDER").Range("G15"), Len(Sheets("FINALORDER").Range("G15")) - 3, 2) & "/" & Right(Sheets("FINALORDER").Range("G15"), 2)

With oMail
        .SentOnBehalfOfName = "sales@rfbcorp.com"
        .To = Worksheets("DETAIL FORM").Range("G3")
        .cc = ""
        .HTMLBody = "See attached order confirmation. Your order will be released for production. Please notify us immediately if any changes are needed." & "<br/>" & "<br/>" _
                   & "Estimated ship date: " & Holder & "<br/>" & "<br/>" _
                   & "Thank You" & "<br/>" & "<br/>" _
 
Upvote 0
Coming at it another way try (but it is dependent on the answer to my previous question)...

Rich (BB code):
Dim Holder As String
Holder = Left(Sheets("FINALORDER").Range("G15"), Len(Sheets("FINALORDER").Range("G15")) - 4) & "/" & Mid(Sheets("FINALORDER").Range("G15"), Len(Sheets("FINALORDER").Range("G15")) - 3, 2) & "/" & Right(Sheets("FINALORDER").Range("G15"), 2)

With oMail
        .SentOnBehalfOfName = "sales@rfbcorp.com"
        .To = Worksheets("DETAIL FORM").Range("G3")
        .cc = ""
        .HTMLBody = "See attached order confirmation. Your order will be released for production. Please notify us immediately if any changes are needed." & "<br/>" & "<br/>" _
                   & "Estimated ship date: " & Holder & "<br/>" & "<br/>" _
                   & "Thank You" & "<br/>" & "<br/>" _
It works now. I see that you are adding back the slashes. Good enough for me. Thanks!

To answer your previous question:
What in your cell is converting the number 052324 to appear as a date 5/23/24?

I'm using a custom format for that cell: ##"/'##'/'##. this allows an easy entry of 052324 and formats it with the slashes.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
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