Using FindNext to Quantify Change in Rankings Lists

Veter

New Member
Joined
Oct 27, 2008
Messages
7
Hi,
I'm trying to write a simple piece of code that establishes a cell position change in single-word string lists. I have two lists with an identical set of string elements, arranged differently from one another. I use the findnext method to search for the first element of one column in the other column, and then when it is found I offset the value of the difference of the rows (i.e. the cell position change) into a third column. The code that I have so far works well in step by step debugging, but apparent iterations give me very large values. At this later stage, the debugger gives me an error 91 message pointing to the line: Loop While Not a Is Nothing And a.Address <> firstaddress. I have tried to use various for and do loop exits but without sucess. Does anyone have ideas of what could be done? Thank you.

Sub rankchng()
Dim rCell As Range
Dim firstaddress As String

Range("D2:D400").Clear
For Each rCell In Range("b2:b400")
If rCell = Empty Then Exit For

'Worksheets(Rankings).Range("a2:a400").Value = firstaddress
With Range("a2:a400")
Set a = .Find(rCell, LookIn:=xlValues)
If Not a Is Nothing Then
firstaddress = a.Address

Do
'If a = "" Then Exit Do
a.Offset(0, 3).Value = rCell.Row - a.Row

Set a = .findnext(a)

Loop While Not a Is Nothing And a.Address <> firstaddress
End If
End With

Next

End Sub

<!-- / message -->
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Resolved the issue...In the do procedure I put
If IsEmpty(rCell.Offset(0, 3).Value) = False Then GoTo L
'where
L:
Next
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,875
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