我正在尝试编写一个宏代码来执行以下一系列单元格
这用于对输入的数据进行规格检查,以确保数字在规格范围内。谢谢!
我尝试了什么:
Sub SpecCheck()
Dim iRow As Range
Set iRow = Range("f16:l34")
For Each cell In iRow
If cell.Value <> "" And cell.Value > "I6" And cell.Value < "M6" Then
cell.Interior.Color = RGB(255, 0, 0)
End If
Next
End Sub
我试过的新代码,但没有用。也不确定是否重要,但代码是用&#34; general&#34;工作表的代码。
Sub SpecCheck()
Dim iRow As Range, cell As Range
Dim lowSpec As Range
Dim highSpec As Range
Set iRow = Range("f16:l34")
Set lowSpec = Range("r6")
Set highSpec = Range("s6")
For Each cell In iRow
If cell.Value <> "" And cell.Value > highSpec And cell.Value < lowSpec Then
cell.Interior.Color = RGB(255, 0, 0)
End If
Next
End Sub
答案 0 :(得分:1)
您需要指定那些是范围,而不是字符串:
Sub SpecCheck()
Dim iRow As Range, cell as Range ' I also added the cell as Range
Set iRow = Range("f16:l34")
For Each cell In iRow
If cell.Value <> "" And cell.Value > Range("$I$6").Value And cell.Value < Range("$M$6").Value Then
cell.Interior.Color = RGB(255, 0, 0)
End If
Next
End Sub