Double Click Find Macro

juke_juke13

Board Regular
Joined
May 25, 2004
Messages
57
I have the following code and can't quite get it to work as it always tells me the value is not found.

Purpose: Double-click on a cell in Sheet1 and have it look for the value in that cell in Sheet2


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)


Dim Search As String

On Error GoTo ErrorCatch
Search = Target.Value

'Sheet2
Sheets("Holdings").Select

Columns("A:C").Select

Selection.Find(What:=Search, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

Exit Sub

ErrorCatch:
MsgBox "Search item not found"

End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

AD_Taylor

Well-known Member
Joined
May 19, 2011
Messages
687
I'd write that code slightly differently myself as there is no need to select the cells to perform the search.
Here's my version,

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Dim strFind     As String
    Dim rngFind     As Range
    
    Cancel = True
    strFind = Target.Value
    
    Set rngFind = ThisWorkbook.Worksheets("Holdings").Range( _
                    "A:C").Find(What:=strFind, _
                                LookIn:=xlValues, _
                                LookAt:=xlPart, _
                                MatchCase:=False)
        
        
    If rngFind Is Nothing Then
        MsgBox "Search item not found"
    Else
        'If found select the cell containing the term.
        rngFind.Parent.Activate
        rngFind.Select
    End If
End Sub

HTH!
 

juke_juke13

Board Regular
Joined
May 25, 2004
Messages
57
Hope that helps huh? haha

More than helps, thanks a ton! Understanding exactly what VBA code does it a little like reading Spanish for me. I know it sorta, but mostly I just parse my way through procedures I need to execute. it was getting quite aggravating, thanks so much for taking the time to help!
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,090
Messages
5,835,337
Members
430,351
Latest member
ddalton

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top