0
我在Excel VBA(使用Excel 2010)中具有以下代碼,以歐洲格式(dd/mm/yyyy)查找特定日期,然後取消細胞(用它在該日期)下面的行:運行時錯誤消息91(對象變量未設置)
Sub Macro1()
' Macro1
Dim A As Variant
' Input box to insert a date
A = InputBox("Insert date of the last entry with format dd/mm/yyyy", "User date", Format(Now(), "dd/mm/yyyy"))
If IsDate(A) Then
A = Format(CDate(A), "dd/mm/yyyy")
Else
MsgBox "Date in the wrong format!"
End If
'Find the date above, in the variable A, in the Excel sheet
Cells.Find(What:=A, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.EntireRow.Delete
End Sub
然而,當我運行宏,我得到的運行時錯誤消息91
對象變量未設置。
非常感謝您的幫助。
如果搜索範圍包含實際日期(不是文本),那麼您需要使用日期搜索,而不是字符串表示。 'Cells.Find(What:= CDate(A),' –