+ Reply to Thread
Results 1 to 9 of 9

Highlight Active Row macro error

  1. #1
    Registered User
    Join Date
    11-04-2011
    Location
    Rotterdam, Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    15

    Wink Highlight Active Row macro error

    hi,
    I have a macro to highlight the active row of the highlighted cell, but there is one problem. When I save and reopen the workbook, the last row that was highlighted when saved remains permanently highlighted. So if I do this 10 times, I will have 10 rows permanently highlighted.
    the code is as under:


    Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
    Const cnNUMCOLS As Long = 256
    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
    .Item(i).Interior.ColorIndex = nColorIndices(i)
    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
    End With
    End Sub

    So for example if I last click on cell E25, entire row 25 gets highlighted, and when I save and reopen, row 25 remains highlighted no matter what I do.. It cannot be altered!!!

    I need a way to ensure that when I save and reopen, the active cell does not remain permanently highlighted. Thanks in advance!!

  2. #2
    Forum Contributor
    Join Date
    07-07-2005
    Location
    England
    MS-Off Ver
    Office 2019 Enterprise
    Posts
    472

    Re: Highlight Active Row macro error

    how about putting this in the 'ThisWorkbook' object

    Please Login or Register  to view this content.
    this will make the row a blank colour when you press save - if that doesn't work exactly as you need then you might want to try it with the Workbook_Close method

    John

  3. #3
    Registered User
    Join Date
    11-04-2011
    Location
    Rotterdam, Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Highlight Active Row macro error

    hey John,
    Thanks for your reply...
    When I put it under This Workbook, it completely stops working.. and I don't see how the Workbook_Close would help..

    Is there anything I can edit or add to the code to ensure that when I reopen the workbook, it doesn't 'save' or 'remember' the last row highlighted and make it permanent??

    Thanks in advance! really appreciate it!!

  4. #4
    Registered User
    Join Date
    11-04-2011
    Location
    Rotterdam, Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Highlight Active Row macro error

    Oh actually it works perfectly!!!!!

    You rock man!! thank you soo much!!!!!

  5. #5
    Registered User
    Join Date
    11-04-2011
    Location
    Rotterdam, Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Highlight Active Row macro error

    No now it makes all the rows white when saving.. I need it to have no effect when saving

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Highlight Active Row macro error

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

    You obviously haven't bothered reading the Forum Rules. You have already been warned about Code Tags in your previous post. I suggest that if you want our free help then you do so now.
    Last edited by royUK; 11-04-2011 at 06:52 AM.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  7. #7
    Forum Contributor
    Join Date
    07-07-2005
    Location
    England
    MS-Off Ver
    Office 2019 Enterprise
    Posts
    472

    Re: Highlight Active Row macro error

    what do you mean by it makes "all the rows" white. It should only make the current row white (which I am trying to fix now)

  8. #8
    Forum Contributor
    Join Date
    07-07-2005
    Location
    England
    MS-Off Ver
    Office 2019 Enterprise
    Posts
    472

    Re: Highlight Active Row macro error

    If you don't mind row 1 being excluded from the roaming routine then this code should work

    Please Login or Register  to view this content.
    and then in the Before_Save code just get it to go to cell A1 which will put the previous row back to the right colour

    Please Login or Register  to view this content.
    hope that makes sense. If you don't want it to go to cell A1 when the user saves then put the A1 code in the Before_close method

  9. #9
    Registered User
    Join Date
    11-04-2011
    Location
    Rotterdam, Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Highlight Active Row macro error

    Yes works perfectly!!

    Thank you soo much!

+ 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