在继续之前检查范围内的值

所以现在我有一个任务跟踪器的Excel工作簿。 当包含完成date的列被填入时,它将取得该行并将其复制到另一个表(“完成”),然后从当前表(“当前”)中删除它。 在执行此操作之前,我希望执行的操作是检查“C”或“U”列的H到M列的值。 如果在该范围内的任何单元格不包含或者,那么我希望它退出并显示一条消息。 我不是要熟悉Excel或VBA,而是使用C ++。

这是现在的代码:

Private Sub Worksheet_Change(ByVal Target As Range) Application.EnableEvents = False Dim receivedDate As Range, nextOpen As Range, isect As Range Set receivedDate = Sheet1.Range("G3:G166") Set isect = Application.Intersect(Target, receivedDate) If Not (isect Is Nothing) And IsDate(Target) = True Then Set nextOpen = Sheet4.Range("A" & Rows.Count).End(xlUp).Offset(1, 0) Target.EntireRow.Copy Destination:=nextOpen.EntireRow Target.EntireRow.Delete End If Application.EnableEvents = True End Sub 

这里是我正在进行的剪辑…

一小部分工作

任何帮助将不胜感激。 对不起,我试着环顾一下。

编辑 – 更强大,添加error handling程序和多单元更新处理

 Private Sub Worksheet_Change(ByVal Target As Range) Dim receivedDate As Range, nextOpen As Range, isect As Range Dim rngHM As Range, c As Range, rngDel As Range Set receivedDate = Sheet1.Range("G3:G166") 'are any of the changed cells in the range we're monitoring? Set isect = Application.Intersect(Target, receivedDate) On Error GoTo haveError 'error handler ensures events get re-enabled... '### remember that Target can contain >1 cell... For Each c In isect.Cells If IsDate(c.Value) Then With c.EntireRow Set rngHM = .Cells(1, "H").Resize(1, 6) 'EDIT: all cells must be C or U If (Application.CountIf(rngHM, "C") + _ Application.CountIf(rngHM, "U")) <> rngHM.Cells.Count Then MsgBox "No C or U on row " & c.Row & " !" Else Set nextOpen = Sheet4.Range("A" & Rows.Count) _ .End(xlUp).Offset(1, 0) .Copy Destination:=nextOpen.EntireRow 'deleting rows while looping gives odd results, ' so store them up until done... If rngDel Is Nothing Then Set rngDel = c Else Set rngDel = Application.Union(rngDel, c) End If End If End With 'entirerow End If 'is date Next c 'delete any copied rows in a single operation If Not rngDel Is Nothing Then Application.EnableEvents = False rngDel.EntireRow.Delete Application.EnableEvents = True End If Exit Sub haveError: 'if your code errors out then this makes sure event handling gets reset Application.EnableEvents = True End Sub