我试图突出显示范围内的非日期值。但是我的代码以某种方式让我突出显示空白单元格, 请告诉我应该改变什么?
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
答案 0 :(得分:0)
使用SpecialCells()
方法循环“常量”(即跳过空白)单元格
Dim MyPlage As Range, cell As Range
Set MyPlage = Range("B2:D6")
For Each cell In MyPlage.SpecialCells(xlCellTypeConstants)
Select Case cell.Value
Case Not IsDate(cell) = False
cell.Interior.Color = 65535
Case Is = "abc"
cell.Interior.ColorIndex = 15
End Select
Next
如果MyPlage
范围内的数据包含公式,则只需将xlCellTypeConstants
更改为xlCellTypeFormulas
答案 1 :(得分:0)
或
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