VBA检查整个范围有效date并不是空白?

I have a workbook like so: Dates 01/02/2017 01/03/2017 BLANK 01/02/2017 

我想运行一个macros,但只有在我的范围内的所有单元格是有效的date,而不是空的。

我正在使用以下:

 Dim cell As Range 'With my workbook, lets check the data With wb.Worksheets(1) Lastrow = .Cells(.Rows.count, "G").End(xlUp).Row 'Data Check: Are all dates valid? For Each cell In Range("E9:E" & Lastrow) If IsDate(cell.Value) And Not IsEmpty(cell.Value) Then Continue Else Exit Sub End If Next End With 

但是这不起作用。 macros仍然运行不pipe什么! 如果这个列中的我的单元格是重要的数据validation列表。

请有人告诉我我要去哪里错了吗?

反转一下逻辑:

  Dim cell As Range 'With my workbook, lets check the data With wb.Worksheets(1) Lastrow = .Cells(.Rows.Count, "G").End(xlUp).Row 'Data Check: Are all dates valid? For Each cell In Range("E9:E" & Lastrow) If Not IsDate(cell.Value) Or Trim(cell.Value) = "" Then Exit Sub End If Next ' the rest of your code. ' it will not get here if there are any blanks in or non dates in the range. End With