Forum Discussion

RubyBlade888's avatar
RubyBlade888
Copper Contributor
Apr 04, 2020
Solved

Giving value based on cell color

Hi all,   is it possible to give value (ex: 1) to a cell based on its background color? basically i want all the grey cell to have value = 1 the number in the pic below was manually typed by me. ...
  • Riny_van_Eekelen's avatar
    Apr 04, 2020

    RubyBlade888 Interesting question. Most of the time one would want to color a cell based on some condition. You want to fill a cell with a number based on its color.

     

    A small bit of VBA in a User Defined Function can read the cell color. Once you know that you can use the color number in an IF statement. Fun to play around with, but I wonder why you would bother to color a cell first (manually, I suppose) and then fill them with a number. Better to select the cells first, put the number in them and then do Conditional Formatting to color all cells based on the number it contains. No need for macros or IF statements.

     

    Anyhow, the attached file contains a working example of what you asked for. Note that the user defined function is (re)executed as soon as you enter something in a cell and press Enter.

Resources