Option Explicit
Sub Autoselect()
Dim Refcolor As Long
Dim RefRow As Long
Dim Refcol As Long
Dim IncRow As Long
Dim RCap As Long
Refcolor = RGB(220, 230, 241)
RefRow = Selection.Row
Refcol = 2 'Will get back to ref column later
RCap = 2000
IncRow = RefRow
Do Until IncRow = RefRow + RCap
If Cells(IncRow, "B").Interior.Color = Refcolor Then
Cells(IncRow, "B").Select
Exit Do
Else
If Cells(IncRow, "B").Value = Nothing Then
Cells(IncRow, "B").Select
Exit Do
Else
End If
IncRow = IncRow + 1
Loop
尝试创建一个函数调用autoselect,它将选择包含颜色RGB(220,230,241)
的单元格或在Column" B"上不包含任何值的单元格。函数的开始将来自selection.row。
答案 0 :(得分:0)
您的错误来自以下声明:
If Cells(IncRow, "B").Value = Nothing Then
Nothing
用于对象,而不是内在类型(字符串,数字,布尔值)。要测试Value
是否为空/空,请使用IsEmpty()
函数:
If IsEmpty(Cells(IncRow, "B").Value) Then