[英]Pull data based from another sheet based on a cell value
I'm very new with VBA.我对 VBA 很陌生。 I have a worksheet "Test" and another sheet "Source" (where data/values will come from).我有一个工作表“测试”和另一个工作表“源”(数据/值的来源)。 I need to pull up the values for all the categories from "Source" sheet based on the value on sheet "Test" cell B2我需要根据工作表“测试”单元格 B2 上的值从“源”工作表中提取所有类别的值
Test sheet:测试表:
Source sheet源表
What I need to happen is depending on the value I put on cell B2 on Test sheet, when I click Retrieve button, other values will be filled out.我需要发生的事情取决于我在测试表上的单元格 B2 上输入的值,当我单击检索按钮时,将填写其他值。
Sub Retrieve()
Sheets("Test").Range("B1").Formula = "=VLOOKUP(B2,Source!$A:$E,1,0)"
Sheets("Test").Range("B3").Formula = "=VLOOKUP(B13,Source!$A:$I,3,0)"
Sheets("Test").Range("B4").Formula = "=VLOOKUP(B13,Source!$A:$I,4,0)"
Sheets("Test").Range("B5").Formula = "=VLOOKUP(B13,Source!$A:$I,5,0)"
End Sub
How do I place an Iferror in the above Vlookup formula?如何在上述 Vlookup 公式中放置 Iferror?
Is this what you are trying?这是你正在尝试的吗?
With Sheets("Test")
.Range("B1").Formula = "=IFERROR(INDEX(Source!$A:$A,MATCH($B$2,Source!$B:$B,0),1),"""")"
.Range("B3").Formula = "=IFERROR(VLOOKUP($B$2,Source!$B:$E,2,0),"""")"
.Range("B4").Formula = "=IFERROR(VLOOKUP($B$2,Source!$B:$E,3,0),"""")"
.Range("B5").Formula = "=IFERROR(VLOOKUP($B$2,Source!$B:$E,4,0),"""")"
End With
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.