View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
sunilpatel sunilpatel is offline
external usenet poster
 
Posts: 57
Default find and findnext


i need to select every cell in coulmn 1 that has a certain string e.g "cat",
then move down until each one is found.
Then following is my attempt!!!!

problem is first cell is never selected and secondly is i need to repeat
code, once with .find and then with .findnext

Can someone please simplify this lot?

Sub FindCat()

Dim CK As Object
Range("A1").Select
ActiveCell.FormulaR1C1 = "CAT"
Range("A2").Select
ActiveCell.FormulaR1C1 = "DOG"
Range("A3").Select
ActiveCell.FormulaR1C1 = "ABIGCAT"
Range("A4").Select
ActiveCell.FormulaR1C1 = "PIG"
Range("A5").Select
ActiveCell.FormulaR1C1 = "NOCAT"
Range("A6").Select
ActiveCell.FormulaR1C1 = "MOUSE"
Range("A7").Select
ActiveCell.FormulaR1C1 = "CAT"
Range("A8").Select

Set CK = Columns(1).Find("CAT")
If Not CK Is Nothing Then
CK.Select
' THEN ASSUME LOTS OF CODE
End If

first% = CK.Row
While CK < ""
Set CK = Columns(1).FindNext(CK) 'try again... as not exact match
If CK Is Nothing Then
End
ElseIf CK < "" Then
CK.Select
' THEN ASSUME LOTS OF CODE
End If
Wend
End Sub