Full Version: Worksheet Module?
UtterAccess Discussion Forums > Microsoft® Office > Microsoft Excel
zocker
Greetings all!

I have just written a cunning little routine that finds Cells which have certain data..This is it:

CODE
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
On Error GoTo errSub:
Dim strSearch As String
strSearch = InputBox("What Property? ", "Find a Property or Owner  ")

'Cells.Find(What:="", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows).Activate

Cells.Find(What:=strSearch, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Activate
'MsgBox Target.Address
errSub:
    If Err.Number = 91 Or Err.Number = 13 Then
        MsgBox "Not found...Try again", , "Co Name"
        Exit Sub
    End If
End Sub


This works really well but (and this is the Question) I have 12 sheets that I want to apply it to...so is there some way I can use it 'globally' and call it also 'globally' from each worksheet?

Many thanks in advance!
StuKiel
Hi James,

You could move this code into the workbook module in the event:

Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Excel.Range, Cancel As Boolean)

As you can see this has the additional reference for the sheet from which the event was triggered.
zocker
Thx.....I'll have a go at that!

Z
StuKiel
Glad to help.
zocker
Thx for your help.........tho it throws this error:

Procedure declaration does not match description of event or procedure having same name

Got any ideas? I dont have any other 'same names' and this error pops on an attempted compile!

Clearly in right direction....event fires any sheet, any cell!

Cheers
Z
Luceze
Hey Z,

Make sure you use Stu's event in the ThisWorkbook module rather than the sheet or standard module.

HTH,
zocker
Thx, got distracted by other projects, i'll start on it again Monday.
Z
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.