Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VBA高亮显示不是范围内日期的单元格_Vba_Date_Highlight - Fatal编程技术网

VBA高亮显示不是范围内日期的单元格

VBA高亮显示不是范围内日期的单元格,vba,date,highlight,Vba,Date,Highlight,我试图突出显示范围内的非日期值。但是,我的代码不知怎么让我强调了空白单元格, 请问我应该换什么 Sub colortest() Set MyPage = Range("B2:D6") For Each cell In MyPage Select Case cell.Value Case Not IsDate(cell) = False cell.Interior.Color = 65535 Case Is = "abc" cell.Inte

我试图突出显示范围内的非日期值。但是,我的代码不知怎么让我强调了空白单元格, 请问我应该换什么

 Sub colortest()
 Set MyPage = Range("B2:D6")
 For Each cell In MyPage
 Select Case cell.Value
 Case Not IsDate(cell) = False
 cell.Interior.Color = 65535
 Case Is = "abc"
 cell.Interior.ColorIndex = 15
 End Select
 Next
 End Sub

Excel屏幕截图

使用
SpecialCells()
方法循环“常量”(即跳过空白)单元格

而如果
MyPlage
范围内的数据有公式,只需将
xlcelltypestants
更改为
xlcelltypeformals

Option Explicit
Public Sub colortest()
    Dim MyPlage As Range, currentCell As Range
    Set MyPlage = Range("B2:D6")

    For Each currentCell In MyPlage
        If Not IsEmpty(currentCell) Then
            Select Case IsDate(currentCell.Value)
            Case 1
                currentCell.Interior.Color = 65535
            Case 0
                currentCell.Interior.Color = 15
            End Select
        End If
    Next currentCell
End Sub
Option Explicit
Public Sub colortest()
    Dim MyPlage As Range, currentCell As Range
    Set MyPlage = Range("B2:D6")

    For Each currentCell In MyPlage
        If Not IsEmpty(currentCell) Then
            Select Case IsDate(currentCell.Value)
            Case 1
                currentCell.Interior.Color = 65535
            Case 0
                currentCell.Interior.Color = 15
            End Select
        End If
    Next currentCell
End Sub