![](/img/trans.png)
[英]Displaying value of one cell or multiple cells based on values in other cells
[英]Is there a way to compare cell values and then colour cells based on the value
我正在尝试比较两列数据(G列和N列)-两者都在同一工作表中。
我正在尝试让我的代码执行以下操作:
Compare the value of N4 with G4.
If N4 is < G4, color red,
If N4 = G4, color yellow,
If N4 > G4, color green.
Repeat this for all active cells in those columns.
自从我使用Macros以来已经有一段时间了,我不知道如何将它们组合在一起。 下面的代码是我所在的位置,但这仅在N列中的值等于“ 7”的情况下才对它进行着色。 这就是我正在努力解决的问题-如何通过将其与G列进行比较来改变颜色? 如果有人可以帮助将其组合在一起,将不胜感激!
我已经尝试过条件格式设置,但是如果N的值在G的%以内,我希望范围添加更多的颜色选项并可能进行编辑。
Sub ColourCode()
lRow = Range("N" & Rows.Count).End(xlUp).Row
Set MR = Range("N4:N" & lRow)
For Each cell In MR
If cell.Value = 7 Then cell.Interior.ColorIndex = 10
Next
End Sub
公式适用于基于固定值的着色-不会与G列进行比较
如果cell.Value
是N列Range("N4:N" & lRow)
一个单元格,则需要偏移-7
列才能从cell
移到G列。
If cell.Value = cell.Offset(ColumnOffset:=-7).Value Then
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.