Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Excel VBA Macro

Options
  • 14-01-2010 5:39pm
    #1
    Registered Users Posts: 8,173 ✭✭✭


    Hi Guys,

    I'm trying to get a Macro which I thought sounded easy. I have a list containing Red, Green and Amber...if a user select Green the Cell should change to Green fill.

    What I have below will only assign the colour when I type Red, Green or Amber and then click another cell.

    Or if I choose one of the colours from my list. Then select another one from the one below, delete it and click another cell. Its really frustrating.

    What I want is if the user selects from the list Red, Green or Amber that the colour change, Don't want them to have type it in. Any Suggestions?

    Thanks in advance
    Sub auto_open()

    ' Run the macro DidCellsChange any time a entry is made in a
    ' cell in Sheet1.
    ThisWorkbook.Worksheets("Overall RAG").OnEntry = "DidCellsChange"

    End Sub


    Sub DidCellsChange()
    Dim KeyCells As String
    ' Define which cells should trigger the KeyCellsChanged macro.
    KeyCells = "A1:A1000"

    ' If the Activecell is one of the key cells, call the
    ' KeyCellsChanged macro.
    If Not Application.Intersect(ActiveCell, Range(KeyCells)) _
    Is Nothing Then KeyCellsChanged

    End Sub

    Sub KeyCellsChanged()
    Dim Cell As Object
    ' If the values in A11:C11 are greater than 50...
    For Each Cell In Range("A2:A1000")
    If Cell = "Red" Then

    ' Make the background color of the cell the 3rd color on the
    ' current palette.
    Cell.Interior.ColorIndex = 3

    End If


    If Cell = "Green" Then

    ' Make the background color of the cell the 3rd color on the
    ' current palette.
    Cell.Interior.ColorIndex = 4

    End If


    If Cell = "Amber" Then

    ' Make the background color of the cell the 3rd color on the
    ' current palette.
    Cell.Interior.ColorIndex = 6

    End If
    Next Cell

    End Sub


Comments

  • Registered Users Posts: 8,173 ✭✭✭Wompa1


    This can be closed. I discovered in Office 2007 I could use Conditional Formatting on my column. Thanks Anyways Guys. You can close this please Mr. Mod!


This discussion has been closed.
Advertisement