Need help pulling values from column - hlookup?

ww2excel

New Member
Joined
Oct 19, 2015
Messages
2
Hi all, so here's my issue.. I need to pull certain values from a single column. The column is formatted so that Product ID's are typically on the top row and the UPC is located on the row directly below (not all Product ID's have UPC codes below them but I need to grab all the ones that do). This column continues on this way for thousands of rows. I need to use my list of Product ID's in Column A to run a lookup and pull the UPC value on the row directly below the ID inside Column B (some will return the next Product ID if a UPC does not exist but I can filter these out later).

Here is an example of my sheet:

Column A:
IDNUM111
IDNUM222
IDNUM333
IDNUM444
IDNUM555

Column B:
IDNUM111
000111
IDNUM222
IDNUM333
IDNUM444
000444

Column A and B are in no particular order. I need some way to run a lookup based on the ID values in Column A and return the row directly below this value in Column B. I'm currently using the hlookup formula =HLOOKUP(A2, $B$2:$B$37960,2,FALSE) but this only returns the first UPC value and then stops. I need this to continue searching down all of my lookup value rows.

Any help would be much appreciated!
 
Last edited:

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Row\Col
A​
B​
C​
D​
E​
1​
2​
2​
IDNUM111 IDNUM111IDNUM111000111
3​
IDNUM222 000111IDNUM444000444
4​
IDNUM333 IDNUM222
5​
IDNUM444 IDNUM333
6​
IDNUM555 IDNUM444
7​
000444

In D1 enter:
Rich (BB code):

=SUM(IF(1-(LEFT($B$2:$B$7,2)="ID"),1))<strike></strike>
In D2 enter and copy down:
Rich (BB code):

=IF($E2="","",INDEX($B$2:$B$7,MATCH($E2,$B$2:$B$7,0)-1))<strike></strike>
In E2 control+shift+enter, not just enter, and copy down:
Rich (BB code):

=IF(ROWS($E$2:E2)<=$D$1,INDEX($B$2:$B$7,SMALL(IF(1-(LEFT($B$2:$B$7,2)="ID"),
    ROW($B$2:$B$7)-ROW($B$2)+1),ROWS($E$2:E2))),"")

Hope this helps.
<strike></strike>
 
Upvote 0
Thanks for the quick response. I should clarify that not all Product ID's begin with "ID". These are a random assortment of letters and numbers that also vary in character lengths. Product UPC numbers also don't always begin with "000" and range in length as well.
 
Upvote 0
How about a macro instead?

Code:
Sub RunThrough()

Dim Key As String
Dim ID As String
Dim UPC As String
Dim Pull As Range
Dim Drop As Range

Dim Check As String

For Each x In Range(Cells(1, 1), Cells(Rows.Count, 1).End(xlUp))
    Key = Cells(x.Row, 1)
    For Each y In Range(Cells(1, 2), Cells(Rows.Count, 2).End(xlUp))
        ID = Cells(y.Row, 2)
        If Key = ID Then
            Set Pull = Cells(y.Row, 2)
                UPC = Pull.Offset(1, 0)
                Check = Left(UPC, 5)
                    If Check <> "IDNUM" Then
                        Set Drop = Cells(x.Row, 3)
                            Drop.Value = UPC
                    End If
                GoTo 1
        End If
    Next
1
Next

End Sub
 
Upvote 0
Thanks for the quick response. I should clarify that not all Product ID's begin with "ID". These are a random assortment of letters and numbers that also vary in character lengths. Product UPC numbers also don't always begin with "000" and range in length as well.

You can expand the macro out to address additional variances within the data:

Code:
Sub RunThrough()

Dim Key As String
Dim ID As String
Dim UPC As String
Dim Pull As Range
Dim Drop As Range

Dim Check As String

For Each X In Range(Cells(1, 1), Cells(Rows.Count, 1).End(xlUp))
    Key = Cells(X.Row, 1)
    For Each y In Range(Cells(1, 2), Cells(Rows.Count, 2).End(xlUp))
        ID = Cells(y.Row, 2)
        If Key = ID Then
            Set Pull = Cells(y.Row, 2)
                UPC = Pull.Offset(1, 0)
                Check = Left(UPC, 5)
                    If Check <> "IDNUM" Then
[COLOR="#FF0000"]                        If Check <> "This" Then
                            If Check <> "That" Then
                                If Check <> "Whatever" Then[/COLOR]
                                    Set Drop = Cells(X.Row, 3)
                                        Drop.Value = UPC
[COLOR="#FF0000"]                                End If
                            End If
                        End If[/COLOR]
                    End If
                GoTo 1
        End If
    Next
1
Next

End Sub
 
Upvote 0
Thanks for the quick response. I should clarify that not all Product ID's begin with "ID". These are a random assortment of letters and numbers that also vary in character lengths. Product UPC numbers also don't always begin with "000" and range in length as well.

A macro would be a good idea here indeed...
 
Upvote 0

Forum statistics

Threads
1,214,990
Messages
6,122,626
Members
449,093
Latest member
catterz66

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