Find 3rd instance of a value in a column

ThomasOES

Board Regular
Joined
Aug 29, 2017
Messages
167
Hello
In a column with multiple names that has some names repeating, I would like to find the third instance of a particular name and then refer to a value two columns over.

For instance if below Name is column A, CS844 is column B, Drift Correct is column C. Lets suppose Rows 1-20.
Currently to find the drift correct value for the first instance of "NIST 293" I use my code below
"NIST 293" appears on Sheets("Report").Range("B6")
Code:
[FONT=Verdana]Range("A1:A20").Find(Sheets("Report").Range("B6")).Offset(,2).Select[/FONT]

Of course this will select the first instance in the column (0.211).
What if I want to select the third instance? (0.217)

NameCS 844Drift Correct
501-676 06840.1340.131
NIST 2930.2160.211
4Q18L10.2050.201
BS CSN 2-20.5470.535
4Q18L20.1970.193
NIST 2910.170.167
501-676 06840.1420.139
NIST 2930.220.216
4Q18L10.2070.203
BS CSN 2-20.540.53
4Q18L20.2050.201
NIST 2910.1750.172
501-676 06840.1350.133
NIST 2930.2210.217
4Q18L10.2040.201
BS CSN 2-20.5470.539
4Q18L20.2060.203
NIST 2910.1470.145
501-676 06840.1350.133

<tbody>
</tbody>

Thanks

Tom
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Try this. Change the data in red for your data

Code:
Sub Find_Instance()


    Dim sh1 As Worksheet, sh2 As Worksheet
    Dim Instance As Double, n As Double
    Dim r As Range, b As Range
    Dim celda As String, existe As Boolean
    
    Set sh1 = Sheets("[COLOR=#ff0000]Sheet1[/COLOR]")
    Set sh2 = Sheets("[COLOR=#ff0000]Report[/COLOR]")
    Instance = [COLOR=#ff0000]3[/COLOR]
    
    sh1.Select
    Set r = sh1.Columns("A")
    Set b = r.Find(sh2.Range("B6").Value, LookAt:=xlWhole, LookIn:=xlValues)
    
    If Not b Is Nothing Then
        celda = b.Address
        n = 1
        Do
            'detalle
            If n = Instance Then
                b.Offset(0, 2).Select
                existe = True
                MsgBox "Found"
                Exit Do
            Else
                n = n + 1
            End If
            Set b = r.FindNext(b)
        Loop While Not b Is Nothing And b.Address <> celda
        If existe = False Then
            MsgBox "There is no instance number : " & Instance
        End If
    Else
        MsgBox "There is no data : " & sh2.Range("B6").Value
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,203,240
Messages
6,054,319
Members
444,717
Latest member
melindanegron

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