Date Format Problem

grady121

Active Member
Joined
May 27, 2005
Messages
385
Office Version
  1. 2016
Platform
  1. Windows
I have a code that inserts a UserForm TextBox2.Value as a date, into Range("J8") - e.g. 01/08/2011.

What I'm trying to do is then copy the date into Range("J9") and covert its into a Date format to the value of "Aug 11"
Or, if I was to enter 01/09/2011 then I would expect to see "Sep 11"

i.e. Just the first 3 letters of the Month & two numbers of the Year.

I'm trying to use the coverted value in Range("J9") as part of a 'Sheet Name', 'Save As' & 'e-Mail' code.

I've tried
Code:
    Range("J9").Value = DateValue(TextBox2.Value)
    Range("J9").Value = Format$(Date, "MMM_YY") ' Change Date format
But it just returns the same month value, regardless of the original date entered.


Any help appreciated.
 
Last edited:

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
That code will always return the current date, that's what the Date function/statement does.:)

Which cell do you want the formatted data to end up in?

If it's J9 you could try this.
Code:
With Range("J9")
    .NumberFormat = "@"
    .Value = Format(DateValue(TextBox2.Value), "mmm-yy")
End With
Or this
Code:
With Range("J9")
       .NumberFormat = "mmm-yy"
       .Value = DateValue(Textbox2.Value)
End With
 
Upvote 0
Thanks for the quick reply Norie.

Also thanks for pointing it out the difference.

The code works great now.

Thanks for your time to reply.
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,753
Members
452,940
Latest member
rootytrip

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