从datepickers中提取日期
问题描述:
我在表格“From”和“To”中有2个日期选择器。我想将这些日期选择器中选择的日期记录在变量中,然后参考给定范围和提取数据之间的输入数据表。我写了一些代码。从datepickers中提取日期
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
example 现在我坚持为我将如何进行相应的日期一致单元真或假。
答
尝试了这一点:
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
所以,你的变量类型是一种错误和OR
只有两个条件之一必须适应。请不要使用.Select
,始终物化.Range, .Cells etc.
。
谢谢队友。我继续使用简单的月份下拉选择器而不是日期选择器。但是这段代码肯定帮了我。非常感谢! –