LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Find function bypass

I don't like relying on the activesheet of a different workbook.

If you know the name of the worksheet in toys.xls, you might as well specify it:

Dim FoundCell As Range
Dim ToysWks As Worksheet

Set ToysWks = Workbooks("Toys.xls").Worksheets("somesheetnameher e")

Set FoundCell = Cells.Find(What:="Toys", After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)

If FoundCell Is Nothing Then End
'not found, do nothing or whatever you want
MsgBox "Toys not found!"
Else
ToysWks.Range("a23").Value = FoundCell.End(xlToRight).Value
End With



carl wrote:

Hi Dave,

Thanks for your help. Being a bit of a beginner I can't get this to work.
I changed it because I assume I couldn't just copy and paste it in to my
script. Either way it's not worked. I changed it to this:

With Cells.Find(What:="Toys", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Dim FoundCell As Range
Set FoundCell = Cells.Find(Toys) 'no .activate here!
If FoundCell Is Nothing Then End
'not found, do nothing or whatever you want
Else
Selection.End(xlToRight).Select
ActiveCell.Select
Selection.Copy
Windows("Toys.xls").Activate
Range("A23").Select
Selection.PasteSpecial Paste:=xlPasteValues
'found it, do the real work.
End With

It stops at the "Else" part saying that it needs "If" after "Else". Am I
doing this all wrong?

"Dave Peterson" wrote:

Dim FoundCell as range

set foundcell = cells.find(....) 'no .activate here!

if foundcell is nothing then
'not found, do nothing or whatever you want
else
'found it, do the real work.
end if


Dave Peterson


--

Dave Peterson


 
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
Bypass a function in a Macro bevchapman Excel Discussion (Misc queries) 3 October 6th 09 04:07 PM
how to bypass password?? funkymonkUK[_182_] Excel Programming 3 June 15th 06 10:46 PM
Bypass Worksheet_Change Sub Matt Excel Programming 3 February 21st 06 09:57 PM
Bypass an Ken Loomis Excel Programming 4 July 3rd 05 04:34 PM
backwards find function to find character in a string of text Ashleigh K. Excel Programming 1 January 14th 04 04:36 PM


All times are GMT +1. The time now is 01:58 AM.

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"