Results 1 to 10 of 17

Thread: Highlight Current Row in Excel (VBA)

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10

    Lightbulb Highlight Current Row in Excel (VBA)

    Hi All,

    Here is a way to highlight the current row.

    This code goes in worksheet module. Right click Tab Name > View code and paste the code there on the VBE window.

    Code:
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        
        '// Developed by Kris @ ExcelFox.com
        
        Dim x, nmRow    As Name
        
        'if A1 holds '0', the macro won't fire
        If Me.Range("A1") = 0 Then Exit Sub 'adjust the flag cell
            
        On Error Resume Next
        Set nmRow = ThisWorkbook.Names("tRow")
        On Error GoTo 0
        
        Const HighlightColor As Long = 6750207 'Adjust the highlight color
    
        If nmRow Is Nothing Then
            Set nmRow = ThisWorkbook.Names.Add("tRow", Target.Row & "|" & Target.EntireRow.Interior.Color, 0)
            Target.EntireRow.Interior.Color = HighlightColor
        Else
            x = Split(Evaluate("tRow"), "|")
            Me.Rows(CLng(x(0))).Interior.Color = IIf(CLng(x(1)) = 16777215, -4142, CLng(x(1)))
            nmRow.RefersTo = Target.Row & "|" & Target.EntireRow.Interior.Color
            Target.EntireRow.Interior.Color = HighlightColor
        End If
    
    End Sub
    Note: This code ensures that you won't lose your row color.

    Enjoy !
    Last edited by Admin; 04-20-2012 at 12:06 PM.
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

Similar Threads

  1. Replies: 4
    Last Post: 06-01-2013, 01:08 PM
  2. Highlight Active Cell’s Row and Column
    By Transformer in forum Tips, Tricks & Downloads (No Questions)
    Replies: 0
    Last Post: 05-17-2013, 12:32 AM
  3. Replies: 6
    Last Post: 05-16-2013, 09:56 AM
  4. Help- Locking column basis current date.
    By Rajesh Kr Joshi in forum Excel Help
    Replies: 1
    Last Post: 03-25-2013, 04:44 PM
  5. Moving Current Latest Data To New Workbook
    By Terry in forum Excel Help
    Replies: 1
    Last Post: 01-19-2013, 12:37 AM

Tags for this Thread

Posting Permissions

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