+ Reply to Thread
Results 1 to 4 of 4

Highlight Active Row macro, and Bold the Active Cell

Hybrid View

StudentTeacher Highlight Active Row macro,... 07-05-2012, 08:22 AM
antoka05 Re: Highlight Active Row... 07-05-2012, 10:59 AM
StudentTeacher Re: Highlight Active Row... 07-05-2012, 02:48 PM
rollis13 Re: Highlight Active Row... 02-08-2013, 07:43 PM
  1. #1
    Registered User
    Join Date
    07-12-2010
    Location
    Midwest, US
    MS-Off Ver
    Excel 2007
    Posts
    13

    Highlight Active Row macro, and Bold the Active Cell

    Hi Programmers,
    I'd like to not only highlight the active row, but also highlight the active cell with bold formatting. I'm using the code from this thread: Highlight Active Row macro error; http://www.excelforum.com/excel-prog...ro-error.html; but don't know how to adapt it.
    Also, if cells happen to already be highlighted or formatted bold, the code should not interfere with this prior formatting.
    Is this possible?
    Lastly, the worksheet should reset to the prior formatting.

    Thanks a bunch.

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

  2. #2
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628

    Re: Highlight Active Row macro, and Bold the Active Cell

    You could try with this code:
    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
    Regards,
    Antonio

  3. #3
    Registered User
    Join Date
    07-12-2010
    Location
    Midwest, US
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Highlight Active Row macro, and Bold the Active Cell

    Hi Antonio,

    Thanks, that works and looks good.
    I'm still having difficulty though resetting it prior to close. For instance, the workbook is saving the yellow highlighting and bold formatting--when the workbook opens again, the row that was last selected has the yellow and bold formatting. How would be the most efficient way of turning this off prior to a save?

    Thanks.

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

    Re: Highlight Active Row macro, and Bold the Active Cell

    Have a try with this attached file (not much testing done).
    Added BeforeClose, BeforeSave and a clearing macro.


    PS. posted in the wrong thread, shoud have been here: http://www.excelforum.com/excel-prog...html?p=3122457
    Attached Files Attached Files
    Last edited by rollis13; 02-19-2013 at 06:57 PM.

+ 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