Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Macro/Method of Importing DATA in a loop | Excel Discussion (Misc queries) | |||
Find Method in For Loop | Excel Programming | |||
xls vba find method to find row that contains the current date | Excel Programming | |||
Copy method of worksheet class failed - loop copying worksheets | Excel Programming | |||
Using variables to make a date and using find method to find that. | Excel Programming |