我想将产品表中列出的产品与图像表中列出的对应图像相关联,以便在名为sheet3的新工作表上获得结果。
例如,我有这个:
产品表:
Product ID
10666
10099
5858
图片表
Image ID Image Url
10666 http://img.mysite.com/images/AB25.jpg
10094 http://img.mysite.com/images/80.jpg
10095 http://img.mysite.com/images/51.jpg
10099 http://img.mysite.com/images/5a.jpg
9765 http://img.mysite.com/images/7c.jpg
9765 http://img.mysite.com/images/b.jpg
9766 http://img.mysite.com/images/e6.jpg
9767 http://img.mysite.com/images/bb.jpg
5858 http://img.mysite.com/66.jpg
5858 http://img.mysite.com/77.jpg
我想要的是sheet3,它向我展示了这个:
Image ID Image Url
10666 http://img.mysite.com/images/AB25.jpg
10099 http://img.mysite.com/images/5a.jpg
5858 http://img.mysite.com/66.jpg
5858 http://img.mysite.com/77.jpg
由于
答案 0 :(得分:0)
你真的不需要vba,但无论如何要试试这个:
Sub HTH()
shtProducts.UsedRange.Resize(, 1).Copy Sheet3.Range("A1")
With Sheet3.Range("A2", Sheet3.Cells(Rows.Count, "A").End(xlUp)).Offset(, 1)
.Formula = "=VLOOKUP(A2,Images!$A:$B,2,FALSE)"
.Value = .Value
End With
End Sub
编辑:
Sub HTH()
Worksheets("images").UsedRange.Resize(, 1).Copy Worksheets("sheet3").Range("A1")
With Worksheets("sheet3").Range("A2", Worksheets("sheet3").Cells(Rows.Count, "A").End(xlUp)).Offset(, 2)
.Formula = "=MATCH(A2,products!$A:$A,0)"
.SpecialCells(xlCellTypeFormulas, xlErrors).EntireRow.Delete
.ClearContents
.Value = .Value
End With
End Sub