findnext

fraufreda

Board Regular
Joined
Oct 14, 2010
Messages
190
Hi.
I'm trying to lookup each value of table1 in table2 giving the second column. In table2 data is sorted.

TABLE1...

LOOKUP VALUERESULT
AA1
AA2
AA3
AA4
BB1
BB2
BB3
CC1
BB1
BB2
BB3

TABLE2..

COL1COL2
AA1
AA2
AA3
AA4
BB1
BB2
BB3
CC1

I TRIED TO USE FINDNEXT TO GIVE ME THE SECOND COL IN THE RESULT BUT IT IS NOT WORKING AND TAKES A LOT OF TIME.

Code:
Dim ws As Worksheet
Dim LRB As Long
Dim cell As Range
Dim Orng As Range
Dim iCounter As Integer
Dim LOOKUPRng As String

Set ws = Sheets("BOM")

   
     LRB = Sheets("bom").Cells(Rows.Count, "F").End(xlUp).Row
    
    With Range("Table5[out]")
            LOOKUPRng = .Find(ComboBox2.Value, , xlValues).Offset(0, 9).Value & "[LOOKUP VALUE]" 
    End With

    For Each cell In ws.Range("A2:A" & LRB)
        With Range(LOOKUPRng)
            Set Orng = .Find(cell.Value, , xlValues)
                iCounter = 2
                Do
                             If Not Orng Is Nothing Then
                                ws.Cells(iCounter, 2).Value = Orng.Offset(0, 1).Value
                                Set Orng = .FindNext(Orng)
                            End If
                Loop While iCounter <= LRB
        End With
    Next
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
AA11
AA22
AA33
AA44
BB11
BB22
BB33
CC11
BB11
BB22
BB33
COL1COL2
AA1I used a helper column to count same letter sequences
AA2
AA3then this macro populated B1:B11
AA4
BB1Sub Macro4()
BB2'
BB3' Macro4 Macro
CC1' Macro recorded 02/10/2017 by bob
'
'
For j = 1 To 11
letter = Cells(j, 1)
numnum = Cells(j, 4)
For z = 16 To 23
If Cells(z, 1) = letter Then GoTo 50 Else GoTo 100
50 mynum = mynum + 1
If mynum = numnum Then Cells(j, 2) = Cells(z, 2): GoTo 200
100 Next z
200 mynum = 0
Next j
End Sub

<colgroup><col span="2"><col span="10"></colgroup><tbody>
</tbody>
 
Upvote 0
yes I suppose, I would put some coding in the front of the macro to produce an array with the helper column numbers in it.

maybe
dim numnum (20)
for y= 1 to 11
numnum(y)=right(cells(y,2),1)
next y

and If mynum = numnum(J) then....

delete row 3 of course
 
Upvote 0

Forum statistics

Threads
1,215,110
Messages
6,123,146
Members
449,098
Latest member
Doanvanhieu

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