locked
Writing a Macro to Fill Cells With Colour RRS feed

  • Question

  • Hi there,

    I was wondering if someone knows a way to automatically fill cells with a certain colour, which corresponds to the value in the cell. ie) cells with 4 should be coloured green, cells with 3 coloured yellow, 2 orange and 1 red.

    Ideally, I would like to be able to run a macro that does this in one click.

    Thanks!

    Monday, July 21, 2014 5:28 PM

Answers

  • You can use conditional formating to do so. If you do want a mmacro use this one (in the sheet module) :

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
       Select Case Target.Value
           Case 4: Target.Interior.ColorIndex = 4
           Case 3: Target.Interior.ColorIndex = 6
           Case 2: Target.Interior.ColorIndex = 45
           Case 1: Target.Interior.ColorIndex = 3
       End Select
    End Sub

    Regards.
    Daniel
     > Hi there,


    I was wondering if someone knows a way to automatically fill cells with a certain colour, which corresponds to the value in the cell. ie) cells with 4 should be coloured green, cells with 3 coloured yellow, 2 orange and 1 red.

    Ideally, I would like to be able to run a macro that does this in one click.

    Thanks!

    ----- http://social.Msdn.microsoft.com/Forums/en-US/exceldev/thread/9eb915fc-a999-41b2-aeea-e267b22e1c4e#9eb915fc-a999-41b2-aeea-e267b22e1c4e
    -----

    • Marked as answer by MaddyRuth Monday, July 21, 2014 6:06 PM
    Monday, July 21, 2014 5:40 PM