在我的表格列B:C中允許日期。我試圖創建一個檢查,看看在C中輸入的日期是否比B更新,如果這麼好,還會提醒用戶並清除內容。 我的代碼返回運行時錯誤91在application.intersect行:Excel VBA在比較日期的兩個單元格時出錯
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Dates As Range
Set Dates = Range("C4:C12")
If Target.Cells.Count > 1 Or IsEmpty(Target) Then
Exit Sub
End If
If Not Application.Intersect(Dates, Range(Target.Address)).Value > ActiveCell.Offset(0, -1).Value Then
GoTo DatesMissMatch
Else
Exit Sub
End If
DatesMissMatch:
Target.ClearContents
ActiveCell.Value = "A2"
MsgBox "Please re-check dates"
End Sub
你會得到什麼錯誤? – MatthewD
當然,對不起...如果不Application.Intersect(日期,範圍(Target.Address))。值> ActiveCell.Offset(0,-1).Value然後 轉到DatesMissMatch –