Setting Combobox to today’s date

Trueblue862

Board Regular
Joined
May 24, 2020
Messages
160
Office Version
  1. 365
Platform
  1. Windows
Hi, I have a Userform with a Combobox which gets its values, a list of dates, from a spreadsheet. I would like to initialise the Userform with the Combobox set to today’s date. I’m using the code below to attempt to achieve this, but it seems to be getting cut off as it enters the first digit into the Combobox, by the Combobox change event which populates a number of TextBoxes dependant on the value in the Combobox. What would be the best way to go about solving this problem? Any help would be appreciated.
VBA Code:
cbxDate.Value=Format(Date,"d/m/yyyy")
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Change the code to. Do you have this code behind the form Initialize?

VBA Code:
       cbxDate.Value=Format(Date,"dd/mm/yyyy")
 
Upvote 0
It sounds like you need to disable the userform's events. Application.EnableEvents doesn't effect userforms, so you have to introduce your own module wide variable and add a testing line to the events you want to control.

VBA Code:
Dim DisableMyEvents As Boolean

Private Sub cbxDate_Change()
    If DisableMyEvents Then Exit Sub
    ' your  change code
End Sub

Sub foo()

    DisableMyEvents = True
    cbxDate.Value=Format(Date,"d/m/yyyy")
    DisableMyEvents = False

Exit Sub
 
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,040
Members
449,063
Latest member
ak94

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