Why can I not get a date in a form text date to format as I want?

kiwicolin

New Member
Joined
Apr 8, 2005
Messages
31
Hi

I have a textbox on my userform that shows the current date when opened. No matter what I try I can not get the format to be in the UK style i.e. dd/mm/yy it always shows the US style mm/dd/yy

It used to work in excel 2003 with txtdate.Value = Format(txtdate, "dd/mm/yy") but fails in 2007 with can't find project or library.
I have also tried Me.txtdate.Value = Format(Me.txtdate.Value, "dd/mm/yy")) with the same result.

Any ideas?

Thank you
 
Last edited:

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.
How do you fill the textbox with the date?
Do you manually enter it when the userform is shown? Or set it in the properties of the textbox at designtime? Or set it to some value at runtime?

My guess is that the stringvalue of the textbox is no longer recognised as a date, and thus cannot be formatted as such.

Try this:
Code:
txtDate.Value = Format(DateValue(txtDate.Value), "dd/mm/yy")
 
Upvote 0
Hi

Thank you for your reply.

It is taken from a cell on the sheet and is in serial format on the sheet.

The code you have suggested has the same error message. It is 'Format' that is highlighted in the debugger when this occurs.

Regards
 
Upvote 0
strange, Format is not in any special library as far as I know... it is a standard function.

Can you try this in the Immediate Window:
Code:
?format(datevalue("12/06/2011"),"dddd dd mmmm yyyy")

Does that also give an error? Or does it reformat the date as expected?
 
Upvote 0
Colin

Sounds like you might have a problem with you references.

Check under Tools>References for anything marked as 'MISSING'.

Note what it is then uncheck it, save your workbook and reopen.

Now try the code.

If that doesn't work post back, and tell us the name, and version if possible, of the reference you unchecked.

By the way, if you want to get the value from the cell as it is on a worksheet then you can use the Text property of the cell instead of Value.

Mind you, if you do have it in serial format on the sheet you will need Format.:)
 
Upvote 0
Norie

That has done the trick and fixed one or two other niggles I was having. Phew thought I was losing the plot and probably was!

Another learning for me.

Many thanks.
 
Upvote 0

Forum statistics

Threads
1,224,591
Messages
6,179,768
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