Advanced Highlighting Rows 2

borgeshugo

New Member
Joined
Jul 29, 2014
Messages
5
My idea is to restore the color index of that row before closing the file.

Is missing the code before I close the workbook.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
    Const cnNUMCOLS As Long = 1056
    Const cnHIGHLIGHTCOLOR As Long = 25  'default lt. yellow
    Static rOld As Range
    Static nColorIndices(1 To cnNUMCOLS) As Long
    Dim i As Long
    Application.ScreenUpdating = False
    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
                If nColorIndices(i) = xlNone Then
                    .Item(i).Interior.ColorIndex = xlNone
                Else
                    .Item(i).Interior.Color = nColorIndices(i)
                End If
            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.Color
            If .Item(i).Interior.ColorIndex = xlNone Then
                nColorIndices(i) = xlNone
            Else
                 nColorIndices(i) = .Item(i).Interior.Color
            End If
        Next i
        .Interior.ColorIndex = cnHIGHLIGHTCOLOR
    End With
    Application.ScreenUpdating = False
End Sub



Private Sub Workbook_BeforeClose(Cancel As Boolean)

??????

End Sub

If someone can help please :confused:

Thank you
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Solved by myself.

I select an unhide cell which is not in use.




Private Sub Workbook_BeforeClose(Cancel As Boolean)

Range("A1").Select

End Sub



</pre>
 
Upvote 0

Forum statistics

Threads
1,216,074
Messages
6,128,649
Members
449,462
Latest member
Chislobog

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top