我需要在列中搜索日期,如果没有找到则停止宏。日期来自Cell
Dim rng1 As Range
Dim strSearch As String
strSearch = Worksheets("Calculations").Cells(4, 3).Value
MyInput.Activate
Set rng1 = Range("H:H").Find(strSearch, , xlValues, xlWhole)
If Not rng1 Is Nothing Then
'Macro follows
Else
MsgBox "Date not found"
End If
End Sub
即使日期存在,此宏的作用始终会返回消息框。
由于
答案 0 :(得分:0)
您正在尝试以字符串类型查找日期。 我刚刚用日期类型将strSearch更改为dteSearch。
Dim rng1 As Range
Dim dteSearch As Date
dteSearch = Worksheets("Calculations").Cells(4, 3).Value
MyInput.Activate
Set rng1 = Range("H:H").Find(dteSearch, , xlValues, xlWhole)
If Not rng1 Is Nothing Then
'Macro follows
Else
MsgBox "Date not found"
End If
End Sub
祝你好运!