Excel – 根据之前值的增加或减less更改单元格颜色

嗨,感谢您的时间,

COLUMN B中,我有一个基于COLUMN A中货币值的货币值:

B1 = A1 * 1.15

由于列A的值:每周波​​动,必须手动input:我想知道是否有增加或减less列B – 我想指出是否有一个颜色的增加或减less。

我遇到的问题是,excel似乎不喜欢引用同一个单元格的值。

如果我正确地理解了你的问题,当你input一个新的数字时,如果A列中的数字与先前input的数字相比已经增加或减less,那么你想操纵B列的颜色,公式与它无关?

我刚刚发布了如何在这里确定单元格的前一个值: 在更改之前,检测单元格中的值

你可以在工作表级应用这样的:

Private Sub Worksheet_Change(ByVal Target As Range) Dim OldValue As Variant, NewValue As Variant 'If in a column other than A then end If Not Target.Column = 1 Then End 'If the entered value is not numeric then clear shade and end If Not IsNumeric(Target.Value) Then Target.Offset(0, 1).Interior.Pattern = xlNone End End If 'Populate NewValue with value of target NewValue = Target.Value 'Turn the events off Application.EnableEvents = False 'Undo the change Application.Undo 'Populate OldValue with the undone value OldValue = Target.Value 'Make the target the NewValue once again Target.Value = NewValue 'Do a comparison on NewValue and OldValue If NewValue > OldValue Then 'Shade Green With Target.Offset(0, 1).Interior .Pattern = xlSolid .Color = 5287936 End With ElseIf NewValue < OldValue Then 'Shade Red With Target.Offset(0, 1).Interior .Pattern = xlSolid .Color = 255 End With Else 'Clear shade Target.Offset(0, 1).Interior.Pattern = xlNone End If Application.EnableEvents = True End Sub