Excel Formula Cell Based on Background color

2019-07-13 01:48发布

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.

enter image description here

Is this possible at all without VBA?

3条回答
叛逆
2楼-- · 2019-07-13 02:28

This can be done from Name Manager this can be accessed by pressing Ctrl+F3.

You will want to create a named reference (i called this "color") and have it refer to =GET.CELL(63,OFFSET(INDIRECT("RC",FALSE),0,-1)) in the formula bar.

Now you can use this 1 cell to the right to determine the color index number of a cell:

Example

So as red is color index 3 in the cell next to it you can apply the formula:

=IF(color=3,1,0)

查看更多
做自己的国王
3楼-- · 2019-07-13 02:47

You can achieve it manually without VBA using an autofilter:

  1. Make sure you have a title above the column with colours and above the column where you want the value 1 placed

  2. Add an Autofilter (Select both columns, click the Filter button on the Data tab of the ribbon)

  3. Click the drop down filter on the column with colours, then click on Filter by Colour, the choose the Red colour

  4. In your second column, enter a 1 in every visible cell. (Enter 1 in the first cell, then fill down. Or, select all cells, type 1 then press ctrl-enter)

查看更多
放荡不羁爱自由
4楼-- · 2019-07-13 02:48

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

then you can use the formula =IsRed(A1) to determine if A1 has a red background

note: this uses the default red in the standard colours

查看更多
登录 后发表回答