Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Ron Ron is offline
external usenet poster
 
Posts: 250
Default Active cell coloured

The cell is GREEN while ACTIVE and turns WHITE after it is no lnger ACTIVE.
If my cell is already colour coded, it loses its colour when no longer
ACTIVE. Can this code be changed so that a cell returns to its ORIGINAL
formmating when no longer ACTIVE?
Code is:


Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target
As Excel.Range)
Static OldCell As Range

If Not OldCell Is Nothing Then
OldCell.Interior.ColorIndex = xlColorIndexNone
End If

Target.Interior.ColorIndex = 4

Set OldCell = Target


End Sub

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8,520
Default Active cell coloured

Try the below

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, _
ByVal Target As Excel.Range)
Static OldCell As Range
Static varIndex As Variant

If Target.Count = 1 Then
If Not OldCell Is Nothing Then OldCell.Interior.ColorIndex = varIndex
varIndex = Target.Interior.ColorIndex
Set OldCell = Target
Target.Interior.ColorIndex = 4
End If

End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Ron" wrote:

The cell is GREEN while ACTIVE and turns WHITE after it is no lnger ACTIVE.
If my cell is already colour coded, it loses its colour when no longer
ACTIVE. Can this code be changed so that a cell returns to its ORIGINAL
formmating when no longer ACTIVE?
Code is:


Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target
As Excel.Range)
Static OldCell As Range

If Not OldCell Is Nothing Then
OldCell.Interior.ColorIndex = xlColorIndexNone
End If

Target.Interior.ColorIndex = 4

Set OldCell = Target


End Sub

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Ron Ron is offline
external usenet poster
 
Posts: 250
Default Active cell coloured

That didn't work. It changed some cells and it didn't hilite others when they
were active. Thank you. Any other ideas?
  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8,520
Default Active cell coloured

In the earlier code I handled a single cell only. A bit more coding is
required to handle a selection or range of cells...Copy pate the entire code
to 'This Workbook' Code module. 1 event code, 2 procedures, and an outside
declaration which remains on top of the 'This Workbook' code module. Try the
below in a new workbook and feedback


Dim arrIndex As Variant
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, _
ByVal Target As Excel.Range)
Static OldCell As Range

If Not OldCell Is Nothing Then ReSetColorIndex OldCell
SetColorIndex Target
Set OldCell = Target
Target.Interior.ColorIndex = 4
End Sub

Sub SetColorIndex(varRange As Range)
Dim intCount As Integer, cell As Object
ReDim arrIndex(varRange.Count)
For Each cell In varRange
intCount = intCount + 1
arrIndex(intCount) = cell.Interior.ColorIndex
Next
End Sub

Sub ReSetColorIndex(varRange As Range)
Dim intCount As Integer, cell As Object
For Each cell In varRange
intCount = intCount + 1
cell.Interior.ColorIndex = arrIndex(intCount)
Next
End Sub


If this post helps click Yes
---------------
Jacob Skaria


"Ron" wrote:

That didn't work. It changed some cells and it didn't hilite others when they
were active. Thank you. Any other ideas?

  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8,520
Default Active cell coloured

If you are making bigger selections; the code will give you an error. To
overcome that change the declaration type of intCount from Integer to the
below in both the procedures.....

intCount As Variant

If this post helps click Yes
---------------
Jacob Skaria


"Jacob Skaria" wrote:

In the earlier code I handled a single cell only. A bit more coding is
required to handle a selection or range of cells...Copy pate the entire code
to 'This Workbook' Code module. 1 event code, 2 procedures, and an outside
declaration which remains on top of the 'This Workbook' code module. Try the
below in a new workbook and feedback


Dim arrIndex As Variant
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, _
ByVal Target As Excel.Range)
Static OldCell As Range

If Not OldCell Is Nothing Then ReSetColorIndex OldCell
SetColorIndex Target
Set OldCell = Target
Target.Interior.ColorIndex = 4
End Sub

Sub SetColorIndex(varRange As Range)
Dim intCount As Integer, cell As Object
ReDim arrIndex(varRange.Count)
For Each cell In varRange
intCount = intCount + 1
arrIndex(intCount) = cell.Interior.ColorIndex
Next
End Sub

Sub ReSetColorIndex(varRange As Range)
Dim intCount As Integer, cell As Object
For Each cell In varRange
intCount = intCount + 1
cell.Interior.ColorIndex = arrIndex(intCount)
Next
End Sub


If this post helps click Yes
---------------
Jacob Skaria


"Ron" wrote:

That didn't work. It changed some cells and it didn't hilite others when they
were active. Thank you. Any other ideas?



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
Coping a Coloured cell The Message Excel Worksheet Functions 4 July 16th 09 01:20 PM
referring to formula in a non active cell from active cell nickname Excel Discussion (Misc queries) 1 June 21st 07 12:11 PM
How can we display the coloured border around the active sheet? BimDim Setting up and Configuration of Excel 1 May 31st 07 02:39 PM
COUNT COLOURED CELL adeel via OfficeKB.com Excel Discussion (Misc queries) 1 May 28th 07 03:25 PM
IF formula & COLOURED CELL littleps New Users to Excel 2 August 1st 05 03:08 PM


All times are GMT +1. The time now is 04:52 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"