Results 1 to 3 of 3
  1. #1
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Change cell Colour (97-->)

    I would like to click into a cell and on doing so make the cell directly to its right change colour. Is this possible?
    Jerry

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Change cell Colour (97-->)

    You can do so using the Worksheet_SelectionChange event. But, execution of VBA code clears the undo buffer, you won't be able to undo actions any more!

    The following code will also remove any background color you have set manually.

    Right-click the sheet tab.
    Select View Code from the popup menu.
    Type or copy/paste the following code:

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Application.EnableEvents = False
    Cells.Interior.ColorIndex = xlColorIndexNone
    Target.Cells(1, 2).Interior.ColorIndex = 3 ' red
    Application.EnableEvents = True
    End Sub

    Change the ColorIndex to your preference.

  3. #3
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Change cell Colour (97-->)

    Brilliant Hans Thanks

    I was nearly there I was setting Ranges, hadn't thought of Target.Cells
    Jerry

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •