vLOOKUP help

jwdemo

Board Regular
Joined
Dec 12, 2013
Messages
188
Office Version
  1. 2013
I am wanting to compare 2 sheets and return only the lines that contain matching UPC values to sheet 3.

Sheet 1 is a long list of products, most of which we do not carry in our store. The sheet contains corrections to some products that have recently been made. These corrections are marked in column A with the reason and are highlighted in green. All items that did NOT change have no data in column A.
Sheet 2 is a list of only products we carry.
Sheet 3 I would like to be a list of items that show up on both sheets and that had a change associated with them.

I would like to take the first UPC in Sheet 2 column C (C2) and look in the entire Sheet 1 column H for a match. If there is a match with an item that contains a change, I'd like the entire line copied into sheet 3.

I can use the excel filter tool to show only those with changes but they don't always start on line 1. Would the vLOOKUP be able to only use the visible items on sheet 1?
 
Since I'm not sure how to post a screenshot ..
My signature block below has several suggestions for posting small screen shots and where to test them.

This would most easily be achieved by a macro, or manual steps that I could outline if needed.

This macro assumes that Sheet3 already exists but anything on it can be cleared.
Test in a copy of your workbook.
Post back with more details if it does not do what you want.

Rich (BB code):
Sub Extract_Changes()
  Dim lc As Long
  Dim rCrit As Range
  
  Sheets("Sheet3").UsedRange.ClearContents
  With Sheets("Sheet1")
    lc = .Cells(1, .Columns.Count).End(xlToLeft).Column
    Set rCrit = .Cells(1, lc + 1).Resize(2)
    rCrit.Cells(2).Formula = "=AND(A2<>"""",ISNUMBER(MATCH(H2,Sheet2!C:C,0)))"
    .Range("A1", .Range("A" & .Rows.Count).End(xlUp)).Resize(, lc).AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=rCrit, _
      CopyToRange:=Sheets("Sheet3").Range("A1"), Unique:=False
    rCrit.ClearContents
  End With
End Sub
 
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Is this comparing column D in Sheet1 and in column H on Sheet2?
No, sorry, I missed that change and was using the columns as described in post #1
I would like to take the first UPC in Sheet 2 column C (C2) and look in the entire Sheet 1 column H for a match.
Try just making these changes shown in red.
Rich (BB code):
rCrit.Cells(2).Formula = "=AND(A2<>"""",ISNUMBER(MATCH(D2,Sheet2!H:H,0)))"
 
Upvote 0
That did it...thanks! Would it be possible to get the macro to paste the line from Sheet 2 instead of the one from Sheet 1? It contains a slightly different bit of information.
 
Upvote 0
That did it...thanks! Would it be possible to get the macro to paste the line from Sheet 2 instead of the one from Sheet 1? It contains a slightly different bit of information.
Try this version.
Rich (BB code):
Sub Extract_Changes_v2()
  Dim lc As Long
  Dim rCrit As Range
  
  Sheets("Sheet3").UsedRange.ClearContents
  With Sheets("Sheet2")
    lc = .Cells(1, .Columns.Count).End(xlToLeft).Column
    Set rCrit = .Cells(1, lc + 1).Resize(2)
    rCrit.Cells(2).Formula = "=COUNTIFS(Sheet1!D:D,H2,Sheet1!A:A,""<>"")"
    .Range("A1", .Range("A" & .Rows.Count).End(xlUp)).Resize(, lc).AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=rCrit, _
      CopyToRange:=Sheets("Sheet3").Range("A1"), Unique:=False
    rCrit.ClearContents
  End With
End Sub
 
Upvote 0
It doesn't seem like it is copying everything over that is on Sheet2. For instance, some of the text in Column N is missing and some of the formatting is different (highlighted cells, etc.) throughout Sheet 3.
 
Upvote 0
For instance, some of the text in Column N is missing
I don't understand what you mean by that.
- Cells have nothing in them that should have text?
- Cell have some text but not all the text that was in Sheet2?
- Something else?


...and some of the formatting is different (highlighted cells, etc.) throughout Sheet 3.
Can you clarify this too please?


Any chance of some dummy sample data that demonstrates the above problems? My signature block below has suggestions for posting small screen shots.
 
Last edited:
Upvote 0
Cells have nothing in them that should have text?
Yes.

Some of the cells have text in them but after they are copied to the other sheet they seem to lose the text. Also, some cells in the sheet are highlighted green but when copied over they don't have the highlighting.
 
Upvote 0
Some of the cells have text in them but after they are copied to the other sheet they seem to lose the text. Also, some cells in the sheet are highlighted green but when copied over they don't have the highlighting.
My sample data is not doing that, so ..
Any chance of some dummy sample data that demonstrates the above problems? My signature block below has suggestions for posting small screen shots.
 
Upvote 0
Peter,

I can't seem to get the Excel Jeanie towork on my Excel 2013. Would it be possible for me to email the file to you to look at?
 
Upvote 0

Forum statistics

Threads
1,215,594
Messages
6,125,723
Members
449,255
Latest member
whatdoido

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