Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Find instruction fails (from foreign sheet)

This code works when I call it from a button on the actual sheet that
has to be querried:

Cells.Find(What:="search something", _
After:=ActiveCell, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, MatchCase:=False).Activate

This code doesn't work and produces an error "1004 - Active method of
Range class failed" when triggered from another sheet than the one
that has to be querried:

Worksheets("Sheet1").Range("Database").Cells.Find( What:="search
something", _
After:=ActiveCell, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, MatchCase:=False).Activate

It must be because of "Worksheets("Sheet1").Range("Database")."... but
what is wrong???

Thanks for any help advice...

Kinne
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Find instruction fails (from foreign sheet)


You have 2 problems, both solved if you activate the sheet before you
search..

After:=ActiveCell <= If Sheet3 is active.. Then the activeCell will
also be on Sheet3... so your find won't work

You activate the cell found.. but you can't activate a cell without
activating it's worksheet first.

With following he'll start searching from the 1st cell in the database
and then Goto the cell (the last True means he'll scroll in such a way
the cell will be in TopLeft corner of screen.


Sub FindIt()

Dim rngFound As Range
With Worksheets("Sheet1").Range("Database")
Set rngFound = .Find( _
What:="search something", _
After:=.Cells(1), _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False)
End With
If rngFound Is Nothing Then Beep Else Application.Goto rngFound, True

End Sub




keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


(Kinne) wrote:

This code works when I call it from a button on the actual sheet that
has to be querried:

Cells.Find(What:="search something", _
After:=ActiveCell, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, MatchCase:=False).Activate

This code doesn't work and produces an error "1004 - Active method of
Range class failed" when triggered from another sheet than the one
that has to be querried:

Worksheets("Sheet1").Range("Database").Cells.Find( What:="search
something", _
After:=ActiveCell, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, MatchCase:=False).Activate

It must be because of "Worksheets("Sheet1").Range("Database")."... but
what is wrong???

Thanks for any help advice...

Kinne


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
Code fails when sheet is protected Tail Wind Excel Discussion (Misc queries) 3 September 4th 07 03:23 PM
Foreign Exchange peterthistle Excel Discussion (Misc queries) 2 November 21st 05 02:19 PM
excel97 vs excel2000 (Find instruction) cyrille New Users to Excel 4 March 4th 05 11:02 PM
excel97 vs excel2000 (Find instruction) cyrille Excel Worksheet Functions 0 February 25th 05 07:26 PM
VBa, Password protected sheet fails to get unprotected with the same password Hans Rattink Excel Programming 3 July 28th 03 02:30 PM


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