fari1
Active Member
- Joined
- May 29, 2011
- Messages
- 362
hi, i've got a code from here, but it is not giving all the find results, just one result 5 times, the code is
it is giving just one result value five times, rather than looping through whole sheet ang giving all the search results
Code:
Sub findBalance()
Dim f As Range, fa As String, i As Long
Dim src As Worksheet, dst As Worksheet
Set src = Sheets("sheet2") 'sheet to be searched, change as required
Set dst = Sheets("sheet3") 'sheet for output, change as required
i = 2
With dst
Set f = src.Cells.Find(What:="CONSOLIDATED", After:=.Cells(1), LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not f Is Nothing Then
fa = f.Value
Do
If Len(f.Value) < 50 Then
.Cells(i, "A") = fa
i = i + 1
End If
Set f = src.Cells.FindNext(f)
Loop Until fa = f.Value
End If
End With
End Sub
it is giving just one result value five times, rather than looping through whole sheet ang giving all the search results