ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Current Cell Color (https://www.excelbanter.com/excel-worksheet-functions/7757-current-cell-color.html)

mike47338

Current Cell Color
 
Is there any way to make a cell change color when you click in it and then go
back to it's original color when you go to another cell and each cell do the
same thing when it is the current cell?

JE McGimpsey

Take a look at Chip Pearson's RowLiner add-in:

http://cpearson.com/excel/rowliner.htm


In article ,
mike47338 wrote:

Is there any way to make a cell change color when you click in it and then go
back to it's original color when you go to another cell and each cell do the
same thing when it is the current cell?


Bob Phillips

This is what I use

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Cells.FormatConditions.Delete
With Target.EntireRow
.FormatConditions.Add Type:=xlExpression, Formula1:="TRUE"
With .FormatConditions(1)
With .Borders(xlTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
With .Borders(xlBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
End With
.FormatConditions(1).Interior.ColorIndex = 20
End With

End Sub


'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"mike47338" wrote in message
...
Is there any way to make a cell change color when you click in it and then

go
back to it's original color when you go to another cell and each cell do

the
same thing when it is the current cell?




mike47338

This works very well except what can I change "With Target.EntireRow" to so
that only the active cell is highlighted?

"Bob Phillips" wrote:

This is what I use

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Cells.FormatConditions.Delete
With Target.EntireRow
.FormatConditions.Add Type:=xlExpression, Formula1:="TRUE"
With .FormatConditions(1)
With .Borders(xlTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
With .Borders(xlBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
End With
.FormatConditions(1).Interior.ColorIndex = 20
End With

End Sub


'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"mike47338" wrote in message
...
Is there any way to make a cell change color when you click in it and then

go
back to it's original color when you go to another cell and each cell do

the
same thing when it is the current cell?





Bob Phillips

Mike,

Just change the line

With Target.Entirerow

to

With Target


--

HTH

RP
(remove nothere from the email address if mailing direct)


"mike47338" wrote in message
...
This works very well except what can I change "With Target.EntireRow" to

so
that only the active cell is highlighted?

"Bob Phillips" wrote:

This is what I use

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Cells.FormatConditions.Delete
With Target.EntireRow
.FormatConditions.Add Type:=xlExpression, Formula1:="TRUE"
With .FormatConditions(1)
With .Borders(xlTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
With .Borders(xlBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
End With
.FormatConditions(1).Interior.ColorIndex = 20
End With

End Sub


'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"mike47338" wrote in message
...
Is there any way to make a cell change color when you click in it and

then
go
back to it's original color when you go to another cell and each cell

do
the
same thing when it is the current cell?







mike47338

Thanks Bob, that is exactly what I was looking for !!

"Bob Phillips" wrote:

Mike,

Just change the line

With Target.Entirerow

to

With Target


--

HTH

RP
(remove nothere from the email address if mailing direct)


"mike47338" wrote in message
...
This works very well except what can I change "With Target.EntireRow" to

so
that only the active cell is highlighted?

"Bob Phillips" wrote:

This is what I use

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Cells.FormatConditions.Delete
With Target.EntireRow
.FormatConditions.Add Type:=xlExpression, Formula1:="TRUE"
With .FormatConditions(1)
With .Borders(xlTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
With .Borders(xlBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
End With
.FormatConditions(1).Interior.ColorIndex = 20
End With

End Sub


'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"mike47338" wrote in message
...
Is there any way to make a cell change color when you click in it and

then
go
back to it's original color when you go to another cell and each cell

do
the
same thing when it is the current cell?








All times are GMT +1. The time now is 08:38 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com