View Full Version : Help needed with a Find Loop function


scott-atkinson
01-18-2008, 04:52 AM
Guys,

Wonder if you can help me.

I have a range of data, and I am trying to find the last cell that has a value of 0 and make this the active cell. The code that I have used is;

Range("p1:p60000").Find(0, lookat:=xlWhole).Select
Do
ActiveCell.FindNext (0)
Loop
ActiveCell.EntireRow.Select

But it does not appear to work...It will find the first cell with value 0 but then the code gives an error record.

What am I doing wrong.

Any advice given would be appreciated.

Thanks

Brianwarnock
01-18-2008, 07:20 AM
I think that your Findnext is incorrect. look in help, but don't you want to use the FindPreviousmethod starting at the end of your range, see help.

Brian

Brianwarnock
01-18-2008, 07:35 AM
This little exercise worked

Sub find0()

Set fc = Worksheets("Sheet1").Range("a1:D7").Find(what:=0)
Set fc = Worksheets("Sheet1").Range("a1:d7").FindPrevious(after:=Range("D7"))
MsgBox "The previous occurrence is in cell " & fc.Address

End Sub