Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 83
Default on double click change cell color

I put this code in the worksheet's code module

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
'on double click change color to show selection

If Not Intersect(Target, Range("A15")) Is Nothing Then
Target.Select
With Selection.Interior
.ColorIndex = 42
.Pattern = xSolid
End With
Cancel = True
End If
End Sub

But the Target is not changing to the desired color. I've tried to change
the Range part to other values and nothing works.
Can anybody see what I'm doing wrong?

As usual any help will be most appreciated!

--
gaba :)
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default on double click change cell color

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
'on double click change color to show selection

If Target.Address = "$A$15" Then
With Target.Interior
.ColorIndex = 42
.Pattern = xlSolid
End With
Cancel = True
End If
End Sub

You misspelled the constant xlSolid

--
Regards,
Tom Ogilvy




"gaba" wrote in message
...
I put this code in the worksheet's code module

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
'on double click change color to show selection

If Not Intersect(Target, Range("A15")) Is Nothing Then
Target.Select
With Selection.Interior
.ColorIndex = 42
.Pattern = xSolid
End With
Cancel = True
End If
End Sub

But the Target is not changing to the desired color. I've tried to change
the Range part to other values and nothing works.
Can anybody see what I'm doing wrong?

As usual any help will be most appreciated!

--
gaba :)



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 83
Default on double click change cell color

:)
Thanks Tom. I'm not feeling pretty smart right now...

"Tom Ogilvy" wrote:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
'on double click change color to show selection

If Target.Address = "$A$15" Then
With Target.Interior
.ColorIndex = 42
.Pattern = xlSolid
End With
Cancel = True
End If
End Sub

You misspelled the constant xlSolid

--
Regards,
Tom Ogilvy




"gaba" wrote in message
...
I put this code in the worksheet's code module

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
'on double click change color to show selection

If Not Intersect(Target, Range("A15")) Is Nothing Then
Target.Select
With Selection.Interior
.ColorIndex = 42
.Pattern = xSolid
End With
Cancel = True
End If
End Sub

But the Target is not changing to the desired color. I've tried to change
the Range part to other values and nothing works.
Can anybody see what I'm doing wrong?

As usual any help will be most appreciated!

--
gaba :)




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default on double click change cell color

Don't feel bad. I missed it too when I tested your code. It is funny that
setting the Pattern to 0 would override the colorindex property (set it to
xlNone / -4142). At least it is not intuitive at first glance.

--
Regards,
Tom Ogilvy



"gaba" wrote in message
...
:)
Thanks Tom. I'm not feeling pretty smart right now...

"Tom Ogilvy" wrote:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
'on double click change color to show selection

If Target.Address = "$A$15" Then
With Target.Interior
.ColorIndex = 42
.Pattern = xlSolid
End With
Cancel = True
End If
End Sub

You misspelled the constant xlSolid

--
Regards,
Tom Ogilvy




"gaba" wrote in message
...
I put this code in the worksheet's code module

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
'on double click change color to show selection

If Not Intersect(Target, Range("A15")) Is Nothing Then
Target.Select
With Selection.Interior
.ColorIndex = 42
.Pattern = xSolid
End With
Cancel = True
End If
End Sub

But the Target is not changing to the desired color. I've tried to

change
the Range part to other values and nothing works.
Can anybody see what I'm doing wrong?

As usual any help will be most appreciated!

--
gaba :)






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 83
Default on double click change cell color

Tom, it's funny you mention the xlNone (are you reading my mind?). That's
what I'm trying to do next...
if I double click on the colored cell, go back to clear color (Pattern set
to 0)

Thanks for your help. I'm teaching myself and some days (like today) small
things look pretty big
Gaba

"Tom Ogilvy" wrote:

Don't feel bad. I missed it too when I tested your code. It is funny that
setting the Pattern to 0 would override the colorindex property (set it to
xlNone / -4142). At least it is not intuitive at first glance.

--
Regards,
Tom Ogilvy



"gaba" wrote in message
...
:)
Thanks Tom. I'm not feeling pretty smart right now...

"Tom Ogilvy" wrote:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
'on double click change color to show selection

If Target.Address = "$A$15" Then
With Target.Interior
.ColorIndex = 42
.Pattern = xlSolid
End With
Cancel = True
End If
End Sub

You misspelled the constant xlSolid

--
Regards,
Tom Ogilvy




"gaba" wrote in message
...
I put this code in the worksheet's code module

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
'on double click change color to show selection

If Not Intersect(Target, Range("A15")) Is Nothing Then
Target.Select
With Selection.Interior
.ColorIndex = 42
.Pattern = xSolid
End With
Cancel = True
End If
End Sub

But the Target is not changing to the desired color. I've tried to

change
the Range part to other values and nothing works.
Can anybody see what I'm doing wrong?

As usual any help will be most appreciated!

--
gaba :)








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default on double click change cell color

Unless you have a need to change the pattern, I would leave it alone. If
you want to toggle the coloration of A15:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
'on double click change color to show selection

If Target.Address = "$A$15" Then
With Target.Interior
If .ColorIndex = xlNone Then
.ColorIndex = 42
Else
.ColorIndex = xlNone
End If

End With
Cancel = True
End If
End Sub

--
Regards,
Tom Ogilvy

"gaba" wrote in message
...
Tom, it's funny you mention the xlNone (are you reading my mind?). That's
what I'm trying to do next...
if I double click on the colored cell, go back to clear color (Pattern set
to 0)

Thanks for your help. I'm teaching myself and some days (like today) small
things look pretty big
Gaba

"Tom Ogilvy" wrote:

Don't feel bad. I missed it too when I tested your code. It is funny

that
setting the Pattern to 0 would override the colorindex property (set it

to
xlNone / -4142). At least it is not intuitive at first glance.

--
Regards,
Tom Ogilvy



"gaba" wrote in message
...
:)
Thanks Tom. I'm not feeling pretty smart right now...

"Tom Ogilvy" wrote:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
'on double click change color to show selection

If Target.Address = "$A$15" Then
With Target.Interior
.ColorIndex = 42
.Pattern = xlSolid
End With
Cancel = True
End If
End Sub

You misspelled the constant xlSolid

--
Regards,
Tom Ogilvy




"gaba" wrote in message
...
I put this code in the worksheet's code module

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
'on double click change color to show selection

If Not Intersect(Target, Range("A15")) Is Nothing Then
Target.Select
With Selection.Interior
.ColorIndex = 42
.Pattern = xSolid
End With
Cancel = True
End If
End Sub

But the Target is not changing to the desired color. I've tried to

change
the Range part to other values and nothing works.
Can anybody see what I'm doing wrong?

As usual any help will be most appreciated!

--
gaba :)








  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 83
Default on double click change cell color

Tom,
YOU are the BEST
g

"Tom Ogilvy" wrote:

Unless you have a need to change the pattern, I would leave it alone. If
you want to toggle the coloration of A15:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
'on double click change color to show selection

If Target.Address = "$A$15" Then
With Target.Interior
If .ColorIndex = xlNone Then
.ColorIndex = 42
Else
.ColorIndex = xlNone
End If

End With
Cancel = True
End If
End Sub

--
Regards,
Tom Ogilvy

"gaba" wrote in message
...
Tom, it's funny you mention the xlNone (are you reading my mind?). That's
what I'm trying to do next...
if I double click on the colored cell, go back to clear color (Pattern set
to 0)

Thanks for your help. I'm teaching myself and some days (like today) small
things look pretty big
Gaba

"Tom Ogilvy" wrote:

Don't feel bad. I missed it too when I tested your code. It is funny

that
setting the Pattern to 0 would override the colorindex property (set it

to
xlNone / -4142). At least it is not intuitive at first glance.

--
Regards,
Tom Ogilvy



"gaba" wrote in message
...
:)
Thanks Tom. I'm not feeling pretty smart right now...

"Tom Ogilvy" wrote:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
'on double click change color to show selection

If Target.Address = "$A$15" Then
With Target.Interior
.ColorIndex = 42
.Pattern = xlSolid
End With
Cancel = True
End If
End Sub

You misspelled the constant xlSolid

--
Regards,
Tom Ogilvy




"gaba" wrote in message
...
I put this code in the worksheet's code module

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
'on double click change color to show selection

If Not Intersect(Target, Range("A15")) Is Nothing Then
Target.Select
With Selection.Interior
.ColorIndex = 42
.Pattern = xSolid
End With
Cancel = True
End If
End Sub

But the Target is not changing to the desired color. I've tried to
change
the Range part to other values and nothing works.
Can anybody see what I'm doing wrong?

As usual any help will be most appreciated!

--
gaba :)









  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default on double click change cell color

Hello,

Regarding the below excellent code used to toggle colors in a cell by double
clicking I have a couple of additional questions. I'm trying to set up a
metric based measurement system using Red-Yellow-Green colors. The idea is to
have the user be able to double click in any cell within a range of cells in
three separate colums (Red-Yellow-Green) to select the color defining the
status of a project(s).

-How do I specify a range of cells in a column that I may wish to double
click in order to change cell color (toggle between color and no-color, i.e.
red)? For example, in this line 'If Target.Address = "$A$15" Then', what do I
need to do to change the single cell to a range of cells, i.e. A15:A20, where
I may double click in any of them to toggle? Also, I need to repeat the same
code for each of the separate colums (each reflecting a different color). How
can I lay this out?

Thank you!


"Tom Ogilvy" wrote:

Unless you have a need to change the pattern, I would leave it alone. If
you want to toggle the coloration of A15:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
'on double click change color to show selection

If Target.Address = "$A$15" Then
With Target.Interior
If .ColorIndex = xlNone Then
.ColorIndex = 42
Else
.ColorIndex = xlNone
End If

End With
Cancel = True
End If
End Sub

--
Regards,
Tom Ogilvy



--
jon


"Tom Ogilvy" wrote:

Unless you have a need to change the pattern, I would leave it alone. If
you want to toggle the coloration of A15:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
'on double click change color to show selection

If Target.Address = "$A$15" Then
With Target.Interior
If .ColorIndex = xlNone Then
.ColorIndex = 42
Else
.ColorIndex = xlNone
End If

End With
Cancel = True
End If
End Sub

--
Regards,
Tom Ogilvy

"gaba" wrote in message
...
Tom, it's funny you mention the xlNone (are you reading my mind?). That's
what I'm trying to do next...
if I double click on the colored cell, go back to clear color (Pattern set
to 0)

Thanks for your help. I'm teaching myself and some days (like today) small
things look pretty big
Gaba

"Tom Ogilvy" wrote:

Don't feel bad. I missed it too when I tested your code. It is funny

that
setting the Pattern to 0 would override the colorindex property (set it

to
xlNone / -4142). At least it is not intuitive at first glance.

--
Regards,
Tom Ogilvy



"gaba" wrote in message
...
:)
Thanks Tom. I'm not feeling pretty smart right now...

"Tom Ogilvy" wrote:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
'on double click change color to show selection

If Target.Address = "$A$15" Then
With Target.Interior
.ColorIndex = 42
.Pattern = xlSolid
End With
Cancel = True
End If
End Sub

You misspelled the constant xlSolid

--
Regards,
Tom Ogilvy




"gaba" wrote in message
...
I put this code in the worksheet's code module

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
'on double click change color to show selection

If Not Intersect(Target, Range("A15")) Is Nothing Then
Target.Select
With Selection.Interior
.ColorIndex = 42
.Pattern = xSolid
End With
Cancel = True
End If
End Sub

But the Target is not changing to the desired color. I've tried to
change
the Range part to other values and nothing works.
Can anybody see what I'm doing wrong?

As usual any help will be most appreciated!

--
gaba :)









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
Cell requires double click to 'activate' date format change BLTibbs Excel Discussion (Misc queries) 4 April 2nd 23 01:38 PM
How to change syperlink from single click to double click syperlinker Excel Worksheet Functions 0 June 13th 08 05:01 PM
Click on graph bar to execute a double-click in a pivot table cell [email protected] Charts and Charting in Excel 4 August 3rd 05 01:37 AM
Change cell back color on click Dave Peterson Excel Discussion (Misc queries) 0 January 24th 05 10:50 PM
how do I: click in cell and make it change color? jasonsweeney Excel Programming 7 January 21st 04 09:17 PM


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