Macro to find next

JDW93

New Member
Joined
Mar 14, 2014
Messages
17
I have a macro which pairs data.

The macro loops by going Next i in a range.

Howevere if the number comes up twice it will only find it in the first instance, can someone suggest somthing which finds the number on the next line instead of the next different number please?
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Hi,
posting your code would help the board.

Sounds like you cound probably use find method with FindNext - have a look in your VBA help file for FindNext Method. There is a a good example there you may be able to adpat.

Dave
 
Upvote 0
For i = 2 To j Step 1
With shData.Range("V2:V" & j)
Set rngFound = .Find(What:=wbk.Cells(i, 1).Value, After:=Range("V3"), LookIn:=xlValues, LookAt:=xlWhole, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)

If Not rngFound Is Nothing Then
myRow = rngFound.Row
Do
'Firstlineof information needed
shData.Cells(myRow, 23) = wbk.Cells(i, 2)

'Second
shData.Cells(myRow, 24) = wbk.Cells(i, 9)


Set rngFound = .FindNext(rngFound)


Loop While Not rngFound Is Nothing And rngFound.Row <> myRow

End If
End With


Next i

End Sub

The code doesnt go to the next row it only finds the next unique number.
 
Upvote 0
Are you sure that your FindNext isn't working? The .Cells write (both first and second line of information) is referenced to a fixed location (myRow doesn't change) so perhaps you keep overwriting what you expect to see?
 
Upvote 0
The Find.next is finding the next number.

But I want to do is to find the information for the next row


number Information

8 Cardiff
8
10 Swansea
13 London

As an example the macro would do the first row containing 8 but then not the second it would jump straight to 10 then 13
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,874
Members
452,363
Latest member
merico17

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