+ Reply to Thread
Results 1 to 3 of 3

[SOLVED] How do I highlight the active cell in a spreadsheet?

  1. #1
    CW
    Guest

    [SOLVED] How do I highlight the active cell in a spreadsheet?

    I want the active cell to change color.

  2. #2
    Peter Rooney
    Guest

    RE: How do I highlight the active cell in a spreadsheet?

    Hi, CW,

    Try pasting this into the code window of the worksheet for which you want to
    highlight the active cell.
    Change the "22" value in the sixth line to change the colour of the highlight.
    Hope this helps

    Pete

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Cells.FormatConditions.Delete
    With Target
    .FormatConditions.Delete
    .FormatConditions.Add Type:=xlExpression, Formula1:="TRUE"
    .FormatConditions(1).Interior.ColorIndex = 22
    End With
    End Sub


    "CW" wrote:

    > I want the active cell to change color.


  3. #3
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243
    Hi,

    The below is also pasted into the worksheet's code, but this allow for any conditional formatting etc that already exists on the sheet to be returned after the active cell is changed rather than deleted as Pete's option does with "Cells.FormatConditions.Delete".

    Check out the link below for further info/instructions.

    Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
    'sourced from http://www.mcgimpsey.com/excel/highl...iteRetainColor
    Const cnNUMCOLS As Long = 10 'if this is 256 it is all columns but macro is slower
    Const cnHIGHLIGHTCOLOR As Long = 36 'default lt. yellow
    Static rOld As Range
    Static nColorIndices(1 To cnNUMCOLS) As Long
    Dim i As Long
    If Not rOld Is Nothing Then 'Restore color indices
    With rOld.Cells
    If .Row = ActiveCell.Row Then Exit Sub 'same row, don't restore
    For i = 1 To cnNUMCOLS
    .Item(i).Interior.ColorIndex = nColorIndices(i)
    Next i
    End With
    End If
    Set rOld = Cells(ActiveCell.Row, 1).Resize(1, cnNUMCOLS)
    With rOld
    For i = 1 To cnNUMCOLS
    nColorIndices(i) = .Item(i).Interior.ColorIndex
    Next i
    .Interior.ColorIndex = cnHIGHLIGHTCOLOR
    End With
    End Sub

    Hth,
    Rob Brockett
    NZ
    Always learning & the best way to learn is to experience...

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1