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

Hello,

I would like to write a macro that changes the color of a cell to red
when it is clicked - could anyone help me with the click or
onmousedown event?

Thanks,
Liglin
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default click event for changing cell color

Liglin,

Put the following code in the ThisWorkbook code module.


Private Sub Workbook_SheetSelectionChange( _
ByVal Sh As Object, ByVal Target As Range)
Static OldCI As Integer
Static OldRng As Range
If Not OldRng Is Nothing Then
OldRng.Interior.ColorIndex = OldCI
End If
OldCI = Target.Interior.ColorIndex
Set OldRng = Target
Target.Interior.ColorIndex = 3 'red
End Sub

You might also be interested in my RowLiner addin at
www.cpearson.com/excel/rowliner.htm .


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"liglin" wrote in message
m...
Hello,

I would like to write a macro that changes the color of a cell

to red
when it is clicked - could anyone help me with the click or
onmousedown event?

Thanks,
Liglin



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default click event for changing cell color

right click sheet tabview codeinsert this. Any cell in column 12 will be
colored red when clicked.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column < 12 Then Exit Sub
Target.Interior.ColorIndex = 3
End Sub

--
Don Guillett
SalesAid Software

"liglin" wrote in message
m...
Hello,

I would like to write a macro that changes the color of a cell to red
when it is clicked - could anyone help me with the click or
onmousedown event?

Thanks,
Liglin



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default click event for changing cell color



Thanks Don.

Is there a way to undo the event? Perhaps with a double click or a left
click?

THanks,
Liglin

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default click event for changing cell color

Use it like a toggle

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column < 12 Then Exit Sub
If Target.Interior.ColorIndex = 3 Then
Target.Interior.ColorIndex = xlColorIndexNone
Else
Target.Interior.ColorIndex = 3
End If
End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Don Guillett" wrote in message
...
right click sheet tabview codeinsert this. Any cell in column 12 will be
colored red when clicked.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column < 12 Then Exit Sub
Target.Interior.ColorIndex = 3
End Sub

--
Don Guillett
SalesAid Software

"liglin" wrote in message
m...
Hello,

I would like to write a macro that changes the color of a cell to red
when it is clicked - could anyone help me with the click or
onmousedown event?

Thanks,
Liglin







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default click event for changing cell color

Liglin,

A slight variation that highlights the whole row

Private Sub Worksheet_Selection(ByVal Target As Range)
Dim sRow As String

Cells.FormatConditions.Delete

With Target.EntireRow
sRow = .Address
.FormatConditions.Add Type:=xlExpression, _
Formula1:="=1=1"
.FormatConditions(1).Interior.ColorIndex = 3
End With

End Sub

It is worksheet event code, so on the target worksheet right-click the sheet
tab, select View Code, and paste the code in.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"liglin" wrote in message
m...
Hello,

I would like to write a macro that changes the color of a cell to red
when it is clicked - could anyone help me with the click or
onmousedown event?

Thanks,
Liglin



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
How to run an event upon changing the value of a specific cell? Wael Fathy Excel Worksheet Functions 1 February 23rd 10 02:04 PM
Is there a double click event for cell? Ayo Excel Discussion (Misc queries) 3 June 6th 08 12:18 AM
changing cell colour on click Nimbus55 Excel Discussion (Misc queries) 3 September 1st 05 01:18 PM
Click event on cell triggers a macro kris Excel Programming 2 November 13th 03 10:42 AM


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