Selection in a multiselect listbox in Userform

Emperor

Board Regular
Joined
Mar 25, 2010
Messages
225
Hi all,

I've got 2 datefields (with a monthview control) in a Userform.

Output are a startdate and an enddate.
Now I wan't to check the dates in my Listbox6 to check if they are between the start/enddate. If so, select them, if not deselect them.

How could I do this?

Thanks in advance!

Mathijs.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
You didn't tell us enough about your setup to be able to give you exact code, so give code structured something like this a try...

Code:
Dim X As Long, StartDate As Date, EndDate As Date
....
....
With ListBox6
  For X = 0 To .ListCount - 1
    If .List(X) >= StartDate And .List(X) <= EndDate Then
      .Selected(X) = True
    Else
      .Selected(X) = False
    End If
  Next
End With
Your use of the word "between" is not entirely clear. The above code assumes you wanted to select any items in the ListBox exactly equal to either the StartDate or the EndDate. If you wanted to exclude them, just change the >= to > and the <= to < in the If..Then test.
 
Upvote 0
While you didnt have all of the information, you did write the code perfectly.
Thanks for your time and effort!

Mathijs.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,291
Members
452,902
Latest member
Knuddeluff

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