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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Excel VBA Macro

  • 14-01-2010 4:39pm
    #1
    Registered Users, Registered Users 2 Posts: 8,193 ✭✭✭


    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, Registered Users 2 Posts: 8,193 ✭✭✭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