combining the date characters from Userform text box to a cell

akram-5

Board Regular
Joined
Feb 25, 2012
Messages
123
Office Version
  1. 2019
Platform
  1. Windows
Hi Guys...
i am trying to put a control on the Date format which the user should enter...
Since i do not see an easy way with one text box, i thought i could create three combo boxes..
One with only Days dropdown, second with Month dropdown and third with Year...

Code:
ComboBox1.List = Array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31")

ComboBox2.List = Array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12")

ComboBox2.List = Array("2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020", "2021", "2022", "2023", "2024", "2025", "2026", "2027", "2028", "2029", "2030")



To combine these three box selections i am using the code below

Code:
DD = ComboBox1.Value
MM = ComboBox2.Value
YY = ComboBox2.Value
ExpiDate = DD & "/" & MM & "/" & YY
ActiveCell.Value = ExpiDate    'agreement Expiry date

The problem occurs if a month like February falls to this entry, they are still able to select the days like 31st or 30th

I want a way to disable those days in this selection according to the last day of the month...
There is another code looking up for the date in this cell and if the user enters a wrong value then its going to be bad..


Thank you so much for reading this and helping me out..
AK
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
There's likely a number of ways to correct this, but without seeing more than what's been posted, one quick way might be to simply test if the date the user 'selected' is a real date and stop the code if it isn't.
Something like this perhaps:
Code:
DD = Me.ComboBox1.Value
MM = Me.ComboBox2.Value
YY = Me.ComboBox3.Value
ExpiDate = DD & "/" & MM & "/" & YY
If Not IsDate(ExpiDate) Then MsgBox "The date entered is not a valid date." & vbNewLine & "Please enter a valid date to continue.": Exit Sub
ActiveCell.Value = ExpiDate    'agreement Expiry date

Does that help?

EDIT:
Oh, and I assumed the second use of 'ComboBox2' was actually meant to be ComboBox3...
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,427
Members
448,961
Latest member
nzskater

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