在Excel表格中,如果有人试图操纵我的标准数据,特定单元格的颜色将被改变

我有3列在我的Excel“优先”,“可用性”和“转身时间”
如果我在优先级栏中input“高”,则根据预定义的标准和公式,自动填充剩余栏(24X7的“可用性”和4小时的“周转时间”)。例如,如果有人操纵数据改变“可用性”从4小时到6小时或其他价值不同于标准,我想改变单元格颜色为红色。感谢提前解决scheme。

如果以这种方式覆盖单元格公式,则可能会遇到问题。 你会以某种方式需要更换公式。 如何不让公式改变呢?

假定以下布局和单元格公式=IF(B3="High","4 hours","")在单元格D3:

在这里输入图像说明

那么像这样的事情呢?

 Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = "$D$3" Then If Not (Range("B3").Value = "High" And Range("D3").Value = "4 hours") Then qm = Chr(34) Range("D3").Formula = "=IF(B3=" & qm & "High" & qm & "," & qm & "4 hours" & qm & "," & qm & qm & ")" End If End If End Sub 

这个代码应该被放置在有问题的表单模块中,而不是一个标准模块。

编辑回应OP评论

顾名思义,条件格式化就是格式化而不是单元格的内容。 如果您接受不允许公式被覆盖的前提,那么您可以考虑在工作表上locking该特定单元格。 这样用户将不能修改单元格或其内容。

欲了解更多信息,请看这个链接 。

使用您要评估的工作表中的“Private Sub Worksheet_Change(ByVal Target As Range)”事件。 示例:如果有人修改单元格J2的值,则将文本颜色更改为红色。

 Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = "$J$2" Then Range("J2").Font.Color = RGB(255, 0, 0) End If End Sub 

使用条件格式:

 Assuming the cell where you want to apply conditional formatting is: B2. 1.Select the cell or cells where you want to apply conditional formatting. 2.Then, click Home > Conditional Formatting > New Rule. 3.In the New Formatting Rule dialog box, click Use a formula to determine which cells to format. 4.Under Format values where this formula is true, type the formula: =AND($B$2<>"24x7",$B$2 <>"20x7") The formula uses the AND function to see if the cell B2 is different from the common values: "24x7", "20x7",... [You can keep adding more values separated by commas in the AND function] If so, the cells are formatted. 5.Click Format. 6.In the Color box, select Red. In the Font Style box, select Bold.