+ Reply to Thread
Results 1 to 6 of 6

Highlight Yellow Active Row, PROBLEM: row selected before closing stays yellow

Hybrid View

  1. #1
    Registered User
    Join Date
    01-29-2013
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    18

    Highlight Yellow Active Row, PROBLEM: row selected before closing stays yellow

    Greetings,
    I found this code on another thread posted last summer

    The code does *exactly* what I wanted it to do: highlight the active row yellow without overwriting any conditional formatting.

    The only problem is: when you save/close the workbook, and re-open, the last row that was selected before closing remains highlighted and it doesn't go away unless you manually select the row and change the fill. This issue was raised by the original poster but no-one ever replied. I hope I'm not breaking any forum rules by reposting.

    Below is the code and attached is a workbook with an example of how the row stays yellow.

    Active Row Highlight Problem Example.xls

    Thank you kindly in advance for your help!!

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
       ' HIGHLIGHT THE ENTIRE ROW YOU HAVE HIGHLIGHTED (ONLY USE ON SHEETS WITH COLOR/FORMATTING COMPLETE)
       Const cnNUMCOLS As Long = 100
       Const cnHIGHLIGHTCOLOR As Long = 36  'default lt. yellow
       Static rOld As Range
       Static nColorIndices(1 To cnNUMCOLS) As Long
       Static nBoldIndices(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
                   With .Item(i)
                       .Interior.ColorIndex = nColorIndices(i)
                       .Font.Bold = nBoldIndices(i)
                   End With
               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
               If .Item(i).Font.Bold Then
                   nBoldIndices(i) = True
               Else
                   nBoldIndices(i) = False
               End If
           Next i
           .Interior.ColorIndex = cnHIGHLIGHTCOLOR
           .Font.Bold = True
       End With
    '        Cells(ActiveCell.Row, "C").Interior.ColorIndex = nColorIndices(3)
    End Sub

  2. #2
    Registered User
    Join Date
    10-20-2012
    Location
    italy
    MS-Off Ver
    Excel 2013
    Posts
    11

    Re: Highlight Yellow Active Row, PROBLEM: row selected before closing stays yellow

    Hi,

    try:
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    'On Error Resume Next
    With ActiveCell
    .EntireRow.Interior.ColorIndex = 36
    End With
    On Error Resume Next
    If [Z1] <> Target.Row Then _
    Rows([Z1]).Interior.ColorIndex = xlNone
    [Z1] = Target.Row
    End Sub

  3. #3
    Registered User
    Join Date
    01-29-2013
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Highlight Yellow Active Row, PROBLEM: row selected before closing stays yellow

    Thank you for the reply! Yes, this has solved the problem of the row staying yellow. The only issue now is ... when I applied it to my actual workbook, the marco is running a bit slow. Every time I move over or down a cell, my mouse changes to the little hour-glass for a second. Any other possible solutions out there?

  4. #4
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    927

    Re: Highlight Yellow Active Row, PROBLEM: row selected before closing stays yellow

    Yesterday I replied to the wrong thread, sorry.
    Take a look at this (if it helps): http://www.excelforum.com/showthread...=1#post3117881

  5. #5
    Registered User
    Join Date
    01-29-2013
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Highlight Yellow Active Row, PROBLEM: row selected before closing stays yellow

    Rollis13 - thank you! That works perfectly.

  6. #6
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    927

    Re: Highlight Yellow Active Row, PROBLEM: row selected before closing stays yellow

    Glad being of some help .

+ 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