简体   繁体   English

根据单元格值从另一张表中提取数据

[英]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.

相关问题 excel根据另一个单元格值从另一个工作表中提取数据 - excel pulling data from another sheet based on another cell value 根据单元格值将数据从一张纸移动到另一张纸 - Moving Data from One Sheet to Another Based on Cell Value 根据单元格值将数据从特定列复制到另一个工作表 - Copy data from specific columns to another sheet based on a cell value 根据第一张工作表中第二个单元格的值,将数据从一个单元格复制到另一张工作表中的单元格? - Copy data from one cell to a cell in another sheet based on the value of a second cell in the first sheet? 根据单元格值将数据从一张表复制并粘贴到另一张表 - Copy and paste data from one sheet to another sheet(s) based on cell value 根据另一个工作表单元格值的值更改工作表中的单元格值 - Change a cell value in a sheet based on the value of another sheet cell value 根据单元格值将特定数据(不是整行!)复制到另一张表 - Copy Specific data (Not the entire row!) to another sheet based on cell value 根据单元格值将行从一个 Excel 工作表复制到另一个 - Copying rows from one Excel sheet to another based on cell value 根据条件将单元格数据从一张纸复制到另一张纸 - copy cell data from one sheet to another based on condtion 根据单元格中的值将行复制到另一张工作表 - Copy row to another sheet based on value in a cell
相关标签
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM