基于背景色的Excel公式单元格 [英] Excel Formula Cell Based on Background color
问题描述
我需要EXCEL中的公式,该公式在单元格背景为红色的单元格旁边的单元格中放置一个数字1.参见下面的示例.
I need a formula in EXCEL that place a number 1 in the cell next to the cell where the cell background is RED. See example below.
没有VBA,这完全有可能吗?
Is this possible at all without VBA?
推荐答案
打开VBA编辑器并添加一个新模块.为此,请转到Developer
选项卡,然后单击Visual Basic
.如果功能区上没有开发人员标签,则需要添加它(进行快速Google搜索).打开VBA编辑器后,右键单击左侧有您的工作簿名称的VBA项目,然后插入一个模块.
Open the VBA editor and add a new module. Do this by going to the Developer
tab and clicking Visual Basic
. If you don't have the developer tab on the ribbon you will need to add it (do a quick Google search). Once the VBA editor is open, right click on the VBA project which has your workbook name on the left and insert a module.
将以下代码放入新模块中:
Place the following code into the new module:
Function IsRed(rng As Range) As Integer
IsRed = (rng.Interior.Color = vbRed) * -1
End Function
然后您可以使用公式=IsRed(A1)
来确定A1
是否具有红色背景
then you can use the formula =IsRed(A1)
to determine if A1
has a red background
注意:这使用标准颜色中的默认红色
这篇关于基于背景色的Excel公式单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!