Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Highlight a row without losing background colors


Hi every one,

I have found this VBA code in McGimpsey & Associates side. It work very
well but the only problem is that went we close the workbook and we open
it later the last selected row before closing during the last time
remained in highlight color.

My idea is to restore the color index of that row before closing the
file.


How can I do this??


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


Thank you and Best Regards


--
Naceur
------------------------------------------------------------------------
Naceur's Profile: http://www.excelforum.com/member.php...o&userid=18943
View this thread: http://www.excelforum.com/showthread...hreadid=386101

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Highlight a row without losing background colors

You would have to use the BeforeSave event in the Thisworkbook module.

You would need to make the variables that store the old color and range in a
general module as public variable (remove the declarations from the
Selectionchange event)

Public rOld As Range
Public nColorIndices(1 To cnNUMCOLS) As Long

This would make them visible both events.

then you could reproduce the code to reset the color in the BeforeSave
event.

See Chip Pearson's page on events if you are not familiar with them
(although you are using one)

http://www.cpearson.com/excel/events.htm

--
Regards,
Tom Ogilvy


"Naceur" wrote in
message ...

Hi every one,

I have found this VBA code in McGimpsey & Associates side. It work very
well but the only problem is that went we close the workbook and we open
it later the last selected row before closing during the last time
remained in highlight color.

My idea is to restore the color index of that row before closing the
file.


How can I do this??


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


Thank you and Best Regards


--
Naceur
------------------------------------------------------------------------
Naceur's Profile:

http://www.excelforum.com/member.php...o&userid=18943
View this thread: http://www.excelforum.com/showthread...hreadid=386101



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 691
Default Highlight a row without losing background colors

I think Chip Pearson's row liner addin is a better solution, since you
are less likely to change the cell border colors. Of course you would
be sent there from the other page of his.
RowLiner Add-In
http://www.cpearson.com/excel/RowLiner.htm

I think by storing the original colors you still might leave yourself open
to restoring over a color you deliberately changed.
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"Tom Ogilvy" wrote in message ...
You would have to use the BeforeSave event in the Thisworkbook module.

You would need to make the variables that store the old color and range in a
general module as public variable (remove the declarations from the
Selectionchange event)

Public rOld As Range
Public nColorIndices(1 To cnNUMCOLS) As Long

This would make them visible both events.

then you could reproduce the code to reset the color in the BeforeSave
event.

See Chip Pearson's page on events if you are not familiar with them
(although you are using one)

http://www.cpearson.com/excel/events.htm

--
Regards,
Tom Ogilvy


"Naceur" wrote in
message ...

Hi every one,

I have found this VBA code in McGimpsey & Associates side. It work very
well but the only problem is that went we close the workbook and we open
it later the last selected row before closing during the last time
remained in highlight color.

My idea is to restore the color index of that row before closing the
file.


How can I do this??


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


Thank you and Best Regards


--
Naceur
------------------------------------------------------------------------
Naceur's Profile:

http://www.excelforum.com/member.php...o&userid=18943
View this thread: http://www.excelforum.com/showthread...hreadid=386101





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chart background colors by value Barbie Charts and Charting in Excel 1 April 22nd 10 08:13 PM
functions with background colors Marcelo Excel Worksheet Functions 4 December 10th 07 07:53 PM
Lost highlighting and font colors; background colors on web pages Jan in Raleigh Excel Discussion (Misc queries) 2 July 31st 07 09:10 PM
Alternate Background-colors sissi Excel Discussion (Misc queries) 1 August 21st 06 04:16 PM
Copy & Paste Losing Font Colors Mark Tierney Excel Discussion (Misc queries) 1 August 19th 05 08:43 PM


All times are GMT +1. The time now is 10:44 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"