+ Reply to Thread
Results 1 to 4 of 4

Highlight Row of ActiveCell

Hybrid View

  1. #1
    Registered User
    Join Date
    01-17-2013
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Highlight Row of ActiveCell

    I'd like to highlight rows with the activecell. The code below works great for this, but I run the risk of highlighting over my chart header that’s in Rows 1 & 2. Is there an easier way to highlight the active row from columns A to F. I need this to work from Row 3 to Row 100 only.

    Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
        Dim l As Long
        Dim strCells As String
         
         Cells.Range("A3:M100").Interior.ColorIndex = xlColorIndexNone
         
         l = ActiveCell.Row
         strCells = "A" & l & ",B" & l & ",C" & l & ",D" & l & ",E" & l & ",F" & l
        Cells.Range(strCells).Interior.Color = RGB(255, 200, 200)
     End Sub

  2. #2
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Highlight Row of ActiveCell

    How about:

    Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
    Dim l As Long
    Dim strCells As String
         
    Cells.Range("A3:M100").Interior.ColorIndex = xlColorIndexNone
         
    l = ActiveCell.Row
    If l < 3 Or l > 100 Then Exit Sub
    strCells = "A" & l & ":F" & l
    Cells.Range(strCells).Interior.Color = RGB(255, 200, 200)
    End Sub
    Gary's Student

  3. #3
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Highlight Row of ActiveCell

    Another:

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Intersect(Target, Range("A3:F100")) Is Nothing Then
        Rows("3:100").Interior.ColorIndex = xlNone
        Target.EntireRow.Interior.ColorIndex = 6
    End If
    
    End Sub

  4. #4
    Registered User
    Join Date
    01-17-2013
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Highlight Row of ActiveCell

    Thanks everyone. Both worked great. I decided to go with the first option, since I didn't need the entire row highlight, just A:F.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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