Code giving just one result

Status
Not open for further replies.

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

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
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Status
Not open for further replies.

Forum statistics

Threads
1,224,581
Messages
6,179,668
Members
452,936
Latest member
anamikabhargaw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top