Date Picker show based on a combobox value

Blanchetdb

Board Regular
Joined
Jul 31, 2018
Messages
164
Office Version
  1. 365
Platform
  1. Windows
Hi,

I created a UserForm that requires a datepicker to show based on the value of combobox

I tried
Sub End_Date ()
If Me.TxtTenure.value = "Term" Then DTTenure.Show
Else
DTTenure.Hide
End Sub

that didn't work and looked through previous posts and couldn't find exactly what I needed

If one selects "Term" from a dropdown in Combo Box - TextTenure then the date picker shows and they are required to select a date.

can someone help me?

thank you
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Try this, changing ComboBox1 to the name of your combo box.
Code:
Private Sub ComboBox1_Change()

    If ComboBox1.Value = "Term" Then
        DTTenure.Visible = True
    Else
        DTTenure.Visible = False
    End If
    Me.Repaint

End Sub
 
Upvote 0
thanks for the response....

I inserted the coding but there is no change. I am wondering if it because it isn't at the correct place. I presently inserted the coding in the UserForm coding. Should it be somewhere else with a trigger that actions that coding?
 
Upvote 0
The code should go in the userform module and both instances of "ComboBox1" should be changed to the name of your combo box. So if your combo box is named "MyComboBox" the code should be:
Code:
Private Sub MyComboBox_Change()

    If MyComboBox.Value = "Term" Then
        DTTenure.Visible = True
    Else
        DTTenure.Visible = False
    End If
    Me.Repaint

End Sub
 
Upvote 0
thank you.....

It works now.....I had to change one of the properties for date picker box (visible = False) so that it wasn't always visible.

the only issue I have now is that when the information transfers over to the "Inventory" spreadsheet; if the date picker is visible, the date populates the cell (great) but if it isn't , the date doesn't show but the cell is populated with the time 12:00 am .......any thoughts on how to prevent that?
 
Upvote 0
Populating the cell or not depends on your code. Do a simple check like this (in the userform module) in the code which populates the cell:

Code:
If Me.DTPicker1.Visible Then ActiveSheet.Range("B2").Value = Me.DTPicker1.Value
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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