#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Find Macro

I would like to be able to click on a cell and a macro would run that would
highlight all cells in the spreadsheet that have the same value as the cell
that was just clicked. For example if cell A12 has the value "Bob" then if I
left mouse click that cell, all other cells containing the value "Bob" would
be highlighted red. If I click on the cell A13 that has the value "jill" then
all instences of Bob would be unhighlighted and all cells containing the
value Jill would be then highlighted red. I would like this marco function to
work for any cell that is clicked in the A12 to A24 range. The search area
would be A1:A10. Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Find Macro

I don't think it would be too easy to set up a trap for individual mouse
clicks on the worksheet... how about an alternative? The following code will
allow you do double-click on any cell in A12:A24 and it will highlight all
the cells with matching text in A1:A10...

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
Dim C As Range
Dim SourceRange As Range
Dim SearchRange As Range
Set SourceRange = Range("A12:A24")
Set SearchRange = Range("A1:A12")
If Not Intersect(Target, SourceRange) Is Nothing Then
Cancel = True
SearchRange.Interior.ColorIndex = xlNone
For Each C In SearchRange
If C.Value = Target.Value Then
C.Interior.ColorIndex = 3
End If
Next
End If
End Sub

To implement this code, right-click on the tab for the worksheet you want
this to apply to and copy/paste the above code into the code window that
appeared. Then, go back to the worksheet and double click a name in the
range A12:A24 and watch what happens in the range A1:A10.

Rick



"Prohock" wrote in message
...
I would like to be able to click on a cell and a macro would run that would
highlight all cells in the spreadsheet that have the same value as the
cell
that was just clicked. For example if cell A12 has the value "Bob" then if
I
left mouse click that cell, all other cells containing the value "Bob"
would
be highlighted red. If I click on the cell A13 that has the value "jill"
then
all instences of Bob would be unhighlighted and all cells containing the
value Jill would be then highlighted red. I would like this marco function
to
work for any cell that is clicked in the A12 to A24 range. The search area
would be A1:A10. Thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default Find Macro

Or use the selection change event:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim C As Range
Dim SourceRange As Range
Dim SearchRange As Range
Set SourceRange = Range("A12:A24")
Set SearchRange = Range("A1:A10")
If Not Intersect(Target, SourceRange) Is Nothing Then
SearchRange.Interior.ColorIndex = xlNone
For Each C In SearchRange
If C.Value = Target.Value Then
C.Interior.ColorIndex = 3
End If
Next
End If

End Sub

Cliff Edwards
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Find Macro

Interesting... I could have sworn the OP said right mouse click in his post
which is why I did not suggest the SelectionChange event (figuring he wanted
to be able to click in the cell without triggering the macro)... but I just
re-read his post after seeing your posting... and he did not say "right"
mouse click... he said **left** mouse click... so SelectionChange is
definitely the event to use.

Rick


"ward376" wrote in message
...
Or use the selection change event:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim C As Range
Dim SourceRange As Range
Dim SearchRange As Range
Set SourceRange = Range("A12:A24")
Set SearchRange = Range("A1:A10")
If Not Intersect(Target, SourceRange) Is Nothing Then
SearchRange.Interior.ColorIndex = xlNone
For Each C In SearchRange
If C.Value = Target.Value Then
C.Interior.ColorIndex = 3
End If
Next
End If

End Sub

Cliff Edwards


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Find Macro

Thanks to both of you, the macro does exactly what I would like it to do, you
people are brilliant!

"Rick Rothstein (MVP - VB)" wrote:

Interesting... I could have sworn the OP said right mouse click in his post
which is why I did not suggest the SelectionChange event (figuring he wanted
to be able to click in the cell without triggering the macro)... but I just
re-read his post after seeing your posting... and he did not say "right"
mouse click... he said **left** mouse click... so SelectionChange is
definitely the event to use.

Rick


"ward376" wrote in message
...
Or use the selection change event:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim C As Range
Dim SourceRange As Range
Dim SearchRange As Range
Set SourceRange = Range("A12:A24")
Set SearchRange = Range("A1:A10")
If Not Intersect(Target, SourceRange) Is Nothing Then
SearchRange.Interior.ColorIndex = xlNone
For Each C In SearchRange
If C.Value = Target.Value Then
C.Interior.ColorIndex = 3
End If
Next
End If

End Sub

Cliff Edwards



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
Find & Replace and Find & Insert macro help needed RS Excel Programming 2 January 29th 07 07:35 AM
Get Macro warning, but can't find Macro Stilla Excel Worksheet Functions 1 January 20th 07 01:27 AM
change error message when no more for "find" in macro to find swyltm Excel Programming 1 January 13th 06 05:16 PM
cant find a macro [email protected] Excel Programming 3 July 6th 05 06:50 PM
I need to find a macro to find data cut and paste to another colu. Rex Excel Programming 6 December 7th 04 09:22 AM


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