Vba 从日期选择器中提取日期
我的工作表中有两个日期选择器“From”和“To”。我想将从这些日期选择器中选择的日期记录在变量中,然后参考给定范围和提取数据之间的输入数据表。我写了一些代码Vba 从日期选择器中提取日期,vba,excel,datepicker,excel-2010,Vba,Excel,Datepicker,Excel 2010,我的工作表中有两个日期选择器“From”和“To”。我想将从这些日期选择器中选择的日期记录在变量中,然后参考给定范围和提取数据之间的输入数据表。我写了一些代码 Sub PITimeseries() Dim a As Object Dim b As Object Dim c As Date Set a = DTPicker1.Value Set b = DTPicker2.Value Sheet9.Select Dim rng As Range, cell As Range, rng1 As R
Sub PITimeseries()
Dim a As Object
Dim b As Object
Dim c As Date
Set a = DTPicker1.Value
Set b = DTPicker2.Value
Sheet9.Select
Dim rng As Range, cell As Range, rng1 As Range
Set rng = Range("B5:B71")
Set rng1 = Range("H5:H71")
For Each cell In rng
If cell.Value = a Or cell.Value = b Then
现在我无法确定如何使相应的日期匹配单元格为真或假。尝试以下方法:
Private Sub CommandButton1_Click()
Dim a As Date, b As Date, c As Date
Dim sht As Worksheet
Dim rng As Range, cell As Range, rng1 As Range
Set sht = Worksheets("Sheet9")
Set rng = sht.Range("B5:B71")
Set rng1 = sht.Range("H5:H71")
a = DTPicker1.Value
b = DTPicker2.Value
For Each cell In rng
c = CDate(cell.Value)
If c >= a And c <= b Then
sht.Cells(cell.Row, "H").Value = "True"
Else
sht.Cells(cell.Row, "H").Value = "False"
End If
Next cell
End Sub
Private子命令按钮1\u单击()
尺寸a为日期,b为日期,c为日期
将sht变暗为工作表
变暗rng作为范围、单元格作为范围、rng1作为范围
设置sht=工作表(“表9”)
设置rng=短程范围(“B5:B71”)
设置rng1=短程范围(“H5:H71”)
a=DTPicker1.值
b=DTPicker2.值
对于rng中的每个单元
c=CDate(单元格值)
如果c>=a和c,谢谢大副。我使用了一个简单的月份下拉选择器,而不是日期选择器。但是这个代码确实帮助了我。非常感谢!