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

Maybe dropping the .select's and .activate's would make it easier to
understand--that and using a variable that represents that foundcell:

Dim TermWks as worksheet
dim TermRng as range
dim rngCell as range
Dim FedWks as worksheet
Dim FedRng as range
dim FoundCell as range

set termwks = workbooks("Copy of 2003-07 Terminations.xls") _
.worksheets("sheet999") '<--what's the name of the sheet?

set fedwks = workbooks("Job-Personal-Fed and State Taxes Trimmed-3.xls") _
.worksheets("sheet888") '<--same question here

with termWks
set termrng = .range("b6",.cells(.rows.count,"B").end(xlup))
end with

with FedWks
set fedrng = .cells 'all the sheet
'or???
set fedrng = .range("a:a") 'Just column A???
end with


for each rngcell in termrng.cells
with fedrng
set foundcell = .cells.find(what:=rngcell.value, _
after:=.cells(.cells.count), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows,
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
end with

if foundcell is nothing then
msgbox "Not found!"
else
'do what you want since it was found.
end if
next rngcell

===
Watch for typos. I didn't compile or test this.

Dave Birley wrote:

As any dedicated hacker would do, I have taken some code that works in a
macro and transplanted it. In the original code, I was popping back and forth
between WS in a single WB. This hack involves two WBs:

Windows("Copy of 2003-07 Terminations.xls").Activate
With Range("B6", Range("B" & Rows.Count).End(xlUp)) 'Assume you have
header rows
For Each rngCell In .Cells
rngCell(1, 1).Select
varName = rngCell(1, 1).Value
Selection.Copy
Windows("Job-Personal-Fed and State Taxes Trimmed-3.xls").Activate
Range("A1").Select
Cells.Find(What:=varName, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

..and when I step through it to the Find statement, I get "Object variable
or With block variable not set". I read the help file on this, but couldn't
relate what it was trying to tell me to my code.

Where did I go wrong, mother dear?
--
Dave
Temping with Staffmark
in Rock Hill, SC


--

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
workbook.open throws 1004 error [email protected] Excel Programming 3 April 3rd 06 11:37 PM
How do I perform a certain function if VBA throws up an error? Matt[_37_] Excel Programming 2 February 24th 06 03:06 PM
[Q] Save As throws type mismatch error in control's code? Jason Weiss Excel Discussion (Misc queries) 1 July 16th 05 04:21 AM
Format statement no longer throws an error PF[_2_] Excel Programming 6 March 4th 04 02:44 PM


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