Input box date range in vba?

David_D picture David_D · Oct 17, 2013 · Viewed 32k times · Source

I have an excel file and in the first column (A) i have some dates like this:

17/10/2013
18/10/2013
19/10/2013
20/10/2013
21/10/2013
22/10/2013

The other columns contains some datas. I need create an input box that takes everything inside a date range. I mean; i click the button and it shows me a popup like:

insert start date: 17/10/2013 (i can decide the date)
insert end date: 20/10/2013 (i can decide the date)

and then i can put a macro i've done. So my macro read only datas inside that range. Is it possible?

Answer

user2140261 picture user2140261 · Oct 17, 2013

You can Add a date Time Picker to your use form and test the input for your range as follows:

Open the VBA and the form you want the input on.

In toolbox right click and select additiona controls

enter image description here

Then in the list box select Microsoft Date and Time Picker Control:

enter image description here

Add the control to your form:

enter image description here

then set the code as follows under the DTPicker1_Change() Event:

enter image description here

Private Sub DTPicker1_Change()
If DTPicker1.Value < DateSerial(2013, 10, 20) And DTPicker1.Value > DateSerial(2013, 10, 15) Then
    Debug.Print "Put Your Code Here"
End If
End Sub

change the dates to your own and add your code.

Notes: There are a large amount of settings inside this control, from colors to display types, checkboxes, dropdown style, default values minimum and maximum dates. And also custom Date Formats can be applies based on locale.