VBA changes date format, pls help

mrhonda

Board Regular
Joined
Feb 16, 2011
Messages
50
Hi guy's,

I'm running into some trouble with my userform.

I have one sheet with dates in format dd/mm/yy (european)
These dates are used as input for a combobox in the userform.
The combobox shows the dates as they should be, no problems here.

After a date is selected, the value of the combobox is placed in a cell on my primairy sheet.
The format then is changed to the American style (mm/dd/yy). However the properties of the cell is still European. the date has changed.

For instance. 3-7-2011 = (#40609 =ok) is changed to 7-3-2011 = (#40727 =not ok)

Important for me is that the cell format must be a date, the correct date. Because formulas depend on this value, as a date.

Is there maybe a VBA code that copies the combobox value as a dd/mm/yy format?

Thanks a million
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
You say "the value of the combobox is placed in a cell on my primairy sheet" ... show the line of code that does that.
 
Upvote 0
You need to use CDate:
Code:
range("A1").value = cdate(combobox.value)
for example.
 
Upvote 0
This was the simpel VBA line I used:
Range("F5") = DateBox.Value


Now I changed it to: Range("F5").Value = CDate(DateBox.Value)
And it works like a charm.

Thanks Rorya
 
Upvote 0

Forum statistics

Threads
1,224,582
Messages
6,179,670
Members
452,936
Latest member
anamikabhargaw

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