FindNext doesnt work?

Whistler

Board Regular
Joined
Jul 14, 2011
Messages
61
Hi, i need some help with a code below, in database there are 3 entreys which should be found bat after runnnig the code is returning only first one.

Code:
Sub Go_Click()
Dim ws As Worksheet
Dim ws2 As Worksheet
Set ws = Worksheets("DataBase")
Set ws2 = Worksheets("Review")
Dim What As String
Dim Where As Range
Set Where = ws.Range("B:B")
Dim Found As Range
Dim iRow As Long
Dim firstAddress As String
'find first empty row
iRow = ws2.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).Row
What = ws2.Range("C4")
With Where
Set Found = .Find(What:=What, After:=Range("B2"), LookAt:=xlPart, MatchCase:=False)
 If Not Found Is Nothing Then
    firstAddress = Found.Address
        Do
        Found.Copy
        ws2.Cells(iRow, 2).PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
        Set Found = .FindNext(Found)
        Loop While Not Found Is Nothing And Found.Address <> firstAddress
 End If
End With
End Sub

Thanks for your help
 
I have manage to resolve it, code below if anyone interested:

Code:
Sub Go_Click()
Dim ws, ws2 As Worksheet
Dim Where, Found, Found2, Clear As Range
Dim What, firstAddress As String
Dim iRow As Long
Dim Respond
Dim numRows, numColums
Set ws = Worksheets("DataBase")
Set ws2 = Worksheets("Review")
Set Where = ws.Range("B:B")

What = ws2.Range("C4")
Set Clear = ws2.Range("B6:T30000")
Clear.Clear
With Where
Set Found = .Find(What:=What, After:=Range("B2"), LookAt:=xlWhole, MatchCase:=False)
   
 If Not Found Is Nothing Then
  Found.Copy
    ws2.Cells(4, 10).PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    firstAddress = Found.Address
        Do
        iRow = ws2.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).Row
        numRows = Found.Rows.Count
        numColumns = Found.Columns.Count
        Set Found2 = Union(Found.Offset(0, -1), Found.Offset(0, 1).Resize(, 11))
        Found2.Copy
        ws2.Cells(iRow, 2).PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
        Set Found = .FindNext(Found)
        Loop While Not Found Is Nothing And Found.Address <> firstAddress
 Else
 
 Respond = MsgBox("No records found", vbOKOnly)
 End If
  
End With
End Sub

Thanks for your help
 
Upvote 0

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Adapting the code from post #5
Code:
Do
    ws2.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).Resize(1,11).Value = Found.Resize(1,11).Value
    Set Found = .FindNext(Found)
Loop While Not Found Is Nothing And Found.Address <> firstAddress
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,291
Members
452,902
Latest member
Knuddeluff

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