View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Problem with Find filling a listbox vba

hi,
instead of using "cntend = LastRow(sh)"
try this instead...
lastrow = cells(rows.count,1).End(xlup).row

-----Original Message-----
Hi,

I've got a simple problem (I think)

I would like to search within a selection using the find

method. Then
transfer the found cells to a listbox.

The problem is that the code I'm using loops a "few times

to many".
Does anyone know what's wrong with it?

Here's the code

Private Sub CommandButton2_Click()

Dim sh As Worksheet
Set sh = ThisWorkbook.Worksheets("sheet1")

sh.UsedRange.Activate
cntend = LastRow(sh)


Selection.Find(What:="cash", After:=ActiveCell,

LookIn:=xlValues,
Lookat:=xlPart, SearchOrder:=xlByRows,

SearchDirection:=xlNext,
MatchCase:=True, SearchFormat:=False).Activate
ActiveCell.Select

counter = 1
Do While counter < cntend

Cells.FindNext(After:=ActiveCell).Activate
ListBox1.AddItem ActiveCell.Value
counter = counter + 1

Loop

End Sub


Help Appreciated,

Farmer

.