Date Format?

hallingh

Well-known Member
Joined
Sep 11, 2010
Messages
769
I have some code that sets rsp as a string and equal to the month and year selected by the user from a userform in the format of "Oct-10" or "Feb-11." My code is working great, but when I set a cell on the worksheet equal to rsp it puts it in the format "11-Oct" instead of "Oct-11." Is there anyway I can easily fix this to make it go in the correct format? Here is my code (shortened to show the relevant portions:)

Code:
Dim rsp As String
rsp = Me.MonthBox.Value & "-" & Right(Me.YearBox.Value, 2)
ActiveSheet.Range("F" & CellRow).Value = rsp

CellRow is defined as a long and was given a value earlier. Right now, it is setting the correct cell equal to the correct date, it is just in the incorrect format. Any help would be greatly appreciated.

Thanks!

Hank
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Code:
ActiveSheet.Range("F" & CellRow).Value = DateSerial(Me.YearBox.Value, Me.MonthBox.Value, 1)
ActiveSheet.Range("F" & CellRow).NumberFormat = "mmm-yy"
 
Last edited:
Upvote 0
Hmmm when I ran that it didn't change the cell at all. I changed the second line to read:

Code:
ActiveSheet.Range("F" & CellRow).NumberFormat = "[B]mm[/B]-yy"

Instead of:

Code:
ActiveSheet.Range("F" & CellRow).NumberFormat = "mmm-yy"


Should I not have done that?

Thanks for the help.

Hank
 
Upvote 0
What is in Me.MonthBox.Value ? Text like "Oct" or the month number like 10 ?

And do you want an actual date in cell F? or do you only want the Text of Month-Year?

If Me.MonthBox.Value contains text like "Oct" and you don't want an actual date in cell F then try this...
Code:
ActiveSheet.Range("F" & CellRow).NumberFormat = "@"
ActiveSheet.Range("F" & CellRow).Value = Me.MonthBox.Value & "-" & Right(Me.YearBox.Value, 2)
 
Last edited:
Upvote 0
My combo boxes in the userform are just text values from a range. They are not actual dates.

It doesn't have to populate the cell with a date, it just needs to appear in the format "Oct-10."
 
Upvote 0
I updated post #4.

Format the F cell as Text first...
ActiveSheet.Range("F" & CellRow).NumberFormat = "@" ' Text cell format
...then add your Month-Year text
 
Upvote 0

Forum statistics

Threads
1,214,885
Messages
6,122,085
Members
449,064
Latest member
MattDRT

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