Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 440
Default colour a row by code

If I right click any cell in column "D", how can I get the cells A:M on the
same row to be coloured grey. If right clicked again, A:M to be restored to
original shade (blue)?

Thanks,
--
Traa Dy Liooar

Jock
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default colour a row by code

Try the below..Right click the Sheet tabViewCode and paste the below code to
the code module...


Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, _
Cancel As Boolean)
Application.EnableEvents = False
If Not Application.Intersect(Target, Range("D:D")) Is Nothing Then
Range("A" & Target.Row & ":M" & Target.Row).Interior.ColorIndex = _
IIf(Target.Interior.ColorIndex = 15, 5, 15)
End If
Application.EnableEvents = True
End Sub

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


"Jock" wrote:

If I right click any cell in column "D", how can I get the cells A:M on the
same row to be coloured grey. If right clicked again, A:M to be restored to
original shade (blue)?

Thanks,
--
Traa Dy Liooar

Jock

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default colour a row by code

the issue is saving the cell move 'from' rather than the new cell.

use the rigth click event. open the code page for the sheet, right-click on
the tab and select View Code, then paste this
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As
Boolean)
Static oldRow As Long
Static oldColor As Long
If oldRow < 0 Then
Rows(oldRow).Interior.Color = oldColor
End If
oldColor = Target.Interior.Color
oldRow = Target.Row
Rows(Target.Row).Interior.Color = 12632256
Cancel = True
End Sub



An alternative would be to set conditional formatting

Option Explicit
Sub CF_Example()
With Range("B7:k17")
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=CELL(""Row"")=ROW()"
.FormatConditions(1).Interior.ColorIndex = 15
.Select
End With
End Sub

if you select anycell in the table, then F9, that row within the table will
be grey





"Jock" wrote:

If I right click any cell in column "D", how can I get the cells A:M on the
same row to be coloured grey. If right clicked again, A:M to be restored to
original shade (blue)?

Thanks,
--
Traa Dy Liooar

Jock

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 440
Default colour a row by code

Hi Jacob,
I have used your code and, although it works ok, the right click menu
appears every time (cut, copy, past and so on) it is used.
How can I stop this appearing?
I already had a BeforeDoubleClick event into which I added your code.
Should it be in another on its own?
--
Traa Dy Liooar

Jock


"Jacob Skaria" wrote:

Try the below..Right click the Sheet tabViewCode and paste the below code to
the code module...


Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, _
Cancel As Boolean)
Application.EnableEvents = False
If Not Application.Intersect(Target, Range("D:D")) Is Nothing Then
Range("A" & Target.Row & ":M" & Target.Row).Interior.ColorIndex = _
IIf(Target.Interior.ColorIndex = 15, 5, 15)
End If
Application.EnableEvents = True
End Sub

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


"Jock" wrote:

If I right click any cell in column "D", how can I get the cells A:M on the
same row to be coloured grey. If right clicked again, A:M to be restored to
original shade (blue)?

Thanks,
--
Traa Dy Liooar

Jock

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default colour a row by code

add this line:
Cancel = True

"Jock" wrote in message
...
Hi Jacob,
I have used your code and, although it works ok, the right click menu
appears every time (cut, copy, past and so on) it is used.
How can I stop this appearing?
I already had a BeforeDoubleClick event into which I added your code.
Should it be in another on its own?
--
Traa Dy Liooar

Jock


"Jacob Skaria" wrote:

Try the below..Right click the Sheet tabViewCode and paste the below
code to
the code module...


Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, _
Cancel As Boolean)
Application.EnableEvents = False
If Not Application.Intersect(Target, Range("D:D")) Is Nothing Then
Range("A" & Target.Row & ":M" & Target.Row).Interior.ColorIndex = _
IIf(Target.Interior.ColorIndex = 15, 5, 15)
End If
Application.EnableEvents = True
End Sub

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


"Jock" wrote:

If I right click any cell in column "D", how can I get the cells A:M on
the
same row to be coloured grey. If right clicked again, A:M to be
restored to
original shade (blue)?

Thanks,
--
Traa Dy Liooar

Jock


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
Colour format code LiAD Excel Programming 2 April 30th 09 01:08 PM
Can I rate a cell 1-5 and colour code it? treetop40 Excel Discussion (Misc queries) 5 August 9th 05 05:19 PM
How can I rate a cell 1-5 and colour code it? treetop40 Excel Worksheet Functions 2 August 9th 05 12:15 PM
Code to change interior colour only if current interior colour is BeSmart Excel Programming 2 October 5th 04 12:06 AM
Code to colour Unlocked cells Stuart[_5_] Excel Programming 7 June 1st 04 07:22 PM


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

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

About Us

"It's about Microsoft Excel"