Dav*_*d_D 2 excel vba date-range excel-vba inputbox
我有一个excel文件,在第一列(A)我有一些这样的日期:
17/10/2013
18/10/2013
19/10/2013
20/10/2013
21/10/2013
22/10/2013
Run Code Online (Sandbox Code Playgroud)
其他列包含一些数据.我需要创建一个输入框,将日期范围内的所有内容都包含在内.我的意思是; 我点击按钮,它会显示一个弹出窗口:
insert start date: 17/10/2013 (i can decide the date)
insert end date: 20/10/2013 (i can decide the date)
Run Code Online (Sandbox Code Playgroud)
然后我可以放一个宏我已经完成了.所以我的宏只读取该范围内的数据.可能吗?
use*_*261 12
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

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

Add the control to your form:

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

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
Run Code Online (Sandbox Code Playgroud)
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.
没有特定的日期类型,因此您必须进行一些错误检查.以下是如何从用户获取日期的一个想法:
Dim dateString As String, TheDate As Date
Dim valid As Boolean: valid = True
Do
dateString = Application.InputBox("Enter A Date: ")
If IsDate(dateString) Then
TheDate = DateValue(dateString)
valid = True
Else
MsgBox "Invalid date"
valid = False
End If
Loop Until valid = True
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
28881 次 |
| 最近记录: |