【发布时间】:2024-01-24 10:35:01
【问题描述】:
我正在尝试编写一个宏代码,它将对一系列单元格执行以下操作
- 条件格式仅适用于单元格已输入值的情况
- 如果单元格中的值小于 $I$6 和/或大于 $M$6 ,则突出显示红色,如果不是,则不突出显示(或不应用)。
这用于对输入的数据进行规格检查,以确保数字在规格范围内。谢谢!
我尝试了什么:
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
我尝试了新代码,但没有成功。也不确定是否重要,但代码是用工作表的“通用”代码编写的。
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
【问题讨论】:
-
I'm trying to write a macro code...好吧,那它怎么了...?所以不是"Write code for me site"。向我们展示您到目前为止尝试了什么以及您遇到的问题。 -
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
标签: vba excel conditional-formatting