How do you get cell address of a match using Range.Find

bilten

New Member
Joined
May 20, 2016
Messages
2
I just don't understand the Find method properly. I think. What I am looking for is the Row number at which point the Find method produces a match. The find method is inside a loop setting up a comparison between two ranges on separate sheets, my goal is to capture both the source row and the target row at which a match is found

Code:
Sub SeekFindCopy()
    Dim sourceValue As Variant
    Dim resultOfSeek As Range
    Dim targetRange As Range
 
    LastRow = Sheets("SAP").Range("B" & Rows.Count).End(xlUp).Row
    xMlastRow = Sheets("XM").Range("B" & Rows.Count).End(xlUp).Row
    Set targetRange = Sheets("XM").Range("B:B")
    
    For sRow = 4 To LastRow
    Debug.Print ("sRow is " & sRow)
       
    sourceValue = Sheets("SAP").Range("B" & sRow).Value
    
    Set resultOfSeek = targetRange.Find(what:=sourceValue, After:=targetRange(1))
    Operations = Sheets("SAP").Cells(sRow, "A")
    If resultOfSeek Is Nothing Then
        If Operations = "PROCESS" Then

        End If
    Else
        If Operations = "CHANGED" Then

[B]' At this point I want to get the row number of the targetRange in which the match occurred.[/B]

        ElseIf Operations = "PROCESS" Then

        End If
    End If
    Next sRow
End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Find will return a Range object if, well, it finds what you are trying to find.

To get the Address from that Range object you would use, in your example code anyway, resultOfSeek.Address.

To get the row similarly it would be resultOfSeek.Row.
 
Upvote 0
Thank you very much. That makes sense unfortunately I cannot make it work. I have tried many different wordings but to no avail. The two most likely (In my mind anyway :) being

Code:
Set resultOfSeek = targetRange.Find(what:=sourceValue, After:=targetRange(1))
    xMfoundCell = Sheets("XM").Range(resultOfSeek).Row
            Debug.Print (xMfoundCell)
or

Code:
Set resultOfSeek = targetRange.Find(what:=sourceValue, After:=targetRange(1))
    xMfoundCell = resultOfSeek.Row
        Debug.Print (xMfoundCell)

Please explain like I'm 5

Thank you
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,927
Members
449,094
Latest member
teemeren

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