Results 1 to 16 of 16

Highlight active row but after leaving it give its previous color back

Threaded View

  1. #1
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,785

    Highlight active row but after leaving it give its previous color back

    Hi

    In the attached workbook I have a table to a specific row but after that table I have another section with blue background. I am using the bellow code to highlight the activerow to specific number of columns.
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        Static Rng As Range
        On Error Resume Next
        If Target.Column <= 9 And Target.Row > 1 Then ' This can be modified if the target columns are not in sequence
            Rng.Interior.ColorIndex = xlColorIndexNone
            Set Rng = Range("A" & Target.Row & ":I" & Target.Row)
            Rng.Interior.ColorIndex = 6
        End If
    End Sub
    PROBLEM: The code is working fine as far the table is concerned. but when my selection goes down in the blue section it overright the color
    What I want is to set the color back to the range's previous interior color

    Help would be greatly appreciated.


    Best Regards
    Imran Bhatti
    Attached Files Attached Files
    Last edited by ImranBhatti; 09-15-2017 at 10:50 AM. Reason: correction in code
    Teach me Excel VBA

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Changing Background Color for Active Cells, then back to Previous Color...
    By TMCinDC in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-13-2016, 11:35 AM
  2. Replies: 11
    Last Post: 01-02-2015, 09:21 PM
  3. Go back to previous active sheet
    By gopal baheti in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-02-2014, 09:43 PM
  4. [SOLVED] back to previous active sheet ?
    By Lukael in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-22-2014, 04:45 PM
  5. [SOLVED] Highlight active cell, un-highlight when no longer active?
    By cdterry in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-20-2013, 02:39 PM
  6. [SOLVED] Go back to previous active sheet (Excel 2007)
    By JawD in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-09-2012, 08:00 AM
  7. change highlight color on active cells
    By Louis in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 11-22-2005, 04:45 PM

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