我从以下子中获得了以下内容:根据“JosieP”中的公式值格式化单元格
我正在尝试测试空单元,因为如果遇到空单元,子单元就会失败。如果遇到空单元格,我想为单元格添加颜色
If IsNull(rCell) Then rCell.Interior.Color = 8
不起作用,但也不会失败。
if clng(Left(Right(rcell.value, 2), 1)) < 3 Then rcell.Interior.ColorIndex = 10
当有空单元格时失败。
我尝试添加 Not IsNull(rCell) 所以我会这样做,
if clng(Left(Right(rcell.value, 2), 1)) < 3 And Not IsNull(rCell) Then rcell.Interior.ColorIndex = 10
但这也失败了。
Sub Format()
Dim LastRow As Long
Dim WS As Worksheet
dim rCell as range
Set WS = Sheets("sheet1")
LastRow = WS.range("F" & WS.Rows.Count).End(xlUp).Row
for each rcell in WS.range("F2:F" & LastRow).cells
If IsNull(rCell) Then rCell.Interior.Color = 8
if clng(Left(Right(rcell.value, 2), 1)) < 3 And Not IsNull(rCell) Then rcell.Interior.ColorIndex = 10
next rcell
End Sub