FindNext Problem

Della

New Member
Joined
Mar 10, 2011
Messages
3
Hi guys,

I've been trying to write a code that looks for all references of a given number (Plan6.Cells(conter2, 2)) in a sheet (Plan8), and then pastes the information of other cells in the same row at a different sheet ( the ActiveSheet, Plan7 in this case). The problem is that my FindNext function doesn't work, just the first Find. Because of that my loop runs only one time, since the adresses don't change. Here's the part of the code that's not working

With Plan8.Columns("C")
Set spo = .Find(Plan6.Cells(conter2, 2), LookIn:=xlFormulas, _
lookat:=xlWhole, searchdirection:=xlNext)
firstAddress = spo.Address
Do
ActiveCell.Offset(1, 0).Select
ActiveCell = spo.Offset(0, 1)
Set spo = .FindNext(after:=spo)
Loop While Not spo Is Nothing And spo.Address <> firstAddress
End With


I'm trying to learn vba by myself and by using this forums, so any help would be great.

Best regards from Brazil!
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Welcome to the forums!

Try omitting the After:= part:

Code:
With Plan8.Columns("C")
    Set spo = .Find(Plan6.Cells(conter2, 2), LookIn:=xlFormulas, _
                  lookat:=xlWhole, searchdirection:=xlNext)
    firstAddress = spo.Address
    Do
        ActiveCell.Offset(1, 0).Value = spo.Offset(0, 1).Value
        Set spo = .FindNext([B][COLOR=red]spo[/COLOR][/B])
    Loop While Not spo Is Nothing And spo.Address <> firstAddress
End With
 
Upvote 0
Nope, still goes straight to the End With part.

I have no idea what's wrong, maybe something about the FindNext function is searching at a sheet that's not the active one, i don't know.

The value of Plan6.Cells(conter2, 2) that it looks for in Plan8 is an item, like 4.2.1.1 and i would like the program to get information in all rows that have that item. Then the conter2 variable changes, so that it now looks for the next one, like 4.2.1.2.

Should I post more of the code?

Thanks for the response MrKowz!
 
Upvote 0
Just found out what was wrong! The guy that sends me the sheets with the itens had just typed the first 4.2.1.1 and equaled the other related cells to that one, that's why the FindNext couldn't find anything. Sure looks stupid now, lol

Thanks for the help anyway!
 
Upvote 0

Forum statistics

Threads
1,224,557
Messages
6,179,510
Members
452,918
Latest member
Davion615

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