Insert value into cell based on cell color

  • Hi All, I'm really hoping someone can help me out, i need to be able to automate inserting a value into all cells with a certain color.

    I.e.
    All cells that have a blue background color = insert the value 1
    All cells that have a green background color = insert the value 0.5

    I don't know whether an "if" formula would work or whether there is another way?

    Hope you can help, i'd really appreciate it!

    Thanks

    Chris

  • Re: If cell color = blue (e.g.) then insert value of '1'


    Not very elegant but try:

    Select the range first and then run this macro

    Code
    Sub ValuesInColoredCells()
    Dim c As Range
    For Each c In Selection
    If c.Interior.ColorIndex = 41 Then c.Value = 1  'or colorindex #5
    If c.Interior.ColorIndex = 4 Then c.Value = 0.5  'or colorindex #50
    Next
    End Sub
  • Re: If cell color = blue (e.g.) then insert value of '1'


    Hi
    I would look at using conditional formatting

    Jim
    "The problem with designing vba code completely foolproof is to underestimate the ingenuity of a complete fool."

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!