I have a workbook like so:
Dates
01/02/2017
01/03/2017
BLANK
01/02/2017
我正在尝试运行一个宏,但前提是我范围内的所有单元格都是有效的日期,而不是空的。
我使用的是以下内容:
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
但这不管用。无论发生什么,宏仍然运行!如果重要,本专栏中的单元格是数据验证列表。
有人能告诉我我哪里出了问题吗?
发布于 2017-04-06 19:15:33
稍微颠倒一下逻辑:
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
https://stackoverflow.com/questions/43263618
复制相似问题