【发布时间】:2018-01-06 09:30:55
【问题描述】:
所以我有一个包含多张工作表的工作簿,每张工作表中的每一行用于不同的产品,并且有产品到达的日期以及其他一些信息。
我有一张名为“GRN-Date Search”的表格,允许用户在其中输入特定信息并通过 VBA 搜索表格并复制和粘贴信息。
不过,在让它搜索用户定义的日期范围时,我遇到了困难。
这是我想给你一个想法的约会。我是 VBA 新手,所以我不确定是否可以将 .find 函数用于日期范围?
如果您能提供任何帮助,我们将不胜感激。
Sub DateSearch_Click()
If Range("B3") = "" Then
MsgBox "You must enter a date to search"
Range("B3").Select
Exit Sub
Else
'Clear "GRN-Date Search" Sheet Row through End
Sheets("GRN-Date Search").Range("A7:A" & Rows.Count).EntireRow.Clear
'Set myDate variable to value in B3
myDate = Sheets("GRN-Date Search").Range("B3")
'Set initial Paste Row
nxtRw = 7
'Loop through Sheets 2 - 29
For shtNum = 2 To 29
'Search Column b for date(s)
With Sheets(shtNum).Columns(1)
Set d = .Find(myDate)
If Not d Is Nothing Then
firstAddress = d.Address
Do
'Copy each Row where date is found to next empty Row on Summary sheet
d.EntireRow.Copy Sheets("GRN-Date Search").Range("A" & nxtRw)
nxtRw = nxtRw + 1
Set d = .FindNext(d)
Loop While Not d Is Nothing And d.Address <> firstAddress
End If
End With
Next
End If
End Sub
【问题讨论】: