LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Find Method vs. For...Next Loop

Greetings,
I'm trying to find text in a range. I can do it with a For...Next
Loop, but when I try it with the Find Method, it returns "Nothing."
I've gone over the help file until my eyes started to cross, but I
can't seem to figure out why it wouldn't work. Here's what's working
and what isn't:

---------------------
Dim ToBk As Workbook, FrBk As Workbook, ToSht As Worksheet, FrSht As
Worksheet
Dim ToCl As Range, FrCl As Range, RowNum As Integer, ColNum As
Integer, NumRows As Integer, NumCols As Integer
Dim AppNum As Integer, Cl As Range, LkRng As Range

<snip

AppNum = 172

Set LkRng = FrSht.UsedRange
RowNum = LkRng.Cells.SpecialCells(xlCellTypeLastCell).Row
Set LkRng = FrSht.Range(Cells(1, 2), Cells(RowNum, 2))

<-------------- This routine works correctly -------------------------

For Each Cl In LkRng
If Cl.Value Like "*" & AppNum & "*" Then
Debug.Print Cl.Value & vbLf & Cl.Address
End If
Next Cl

<--------------- This returns Nothing
----------------------------------
Set Cl = LkRng.Find(AppNum, LkRng(1), xlValues, xlWhole, xlByRows,
xlNext, False, False)
Debug.Print Cl.Value & vbLf & Cl.Address

---------------------------

The For...Next Loop returns the correct cell in the range. However,
the Find Method does not return anything. I'd prefer to do this in
one line of code rather than a loop, so if anyone can see what's wrong
with the Find, I'd really appreciate the advice.

XL2003 SP2. This is from a Sub procedure, not a Function procedure (I
learned that Find doesn't work in UDFs from a post back in 2002).

Thanks,
Mike
 
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
Macro/Method of Importing DATA in a loop Faraz A. Qureshi Excel Discussion (Misc queries) 2 August 5th 09 07:34 AM
Find Method in For Loop Sisilla[_2_] Excel Programming 3 May 3rd 07 08:02 PM
xls vba find method to find row that contains the current date RCranston Excel Programming 3 March 28th 07 03:59 PM
Copy method of worksheet class failed - loop copying worksheets lif[_12_] Excel Programming 0 July 31st 06 10:02 PM
Using variables to make a date and using find method to find that. KyWilde Excel Programming 2 April 21st 05 09:43 PM


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