在另一个工作簿中查找匹配的单元格值并返回匹配的行内容

发布于 2024-11-25 09:02:11 字数 251 浏览 1 评论 0原文

我是 Excel 和 VBA 新手,面临以下任务:

我有两个工作簿 - wookbook1.xlsx 包含公司名称并将保存宏,workbook2.xlsx > 它将保存我需要与 workbook1 进行匹配的值。对于 workbook1 中的每个公司名称,我需要获取在 workbook2 中找到匹配项的行值。

请帮忙。

I'm new to Excel and VBA and am faced with the following task:

I have two workbooks - wookbook1.xlsx contains company names and will hold a macro, and workbook2.xlsx which will hold the values I need to match against from workbook1. For each company name in workbook1, I need to get the row value where a match is found in workbook2.

Please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦毁影碎の 2024-12-02 09:02:11

正如 iDevlop 在他/她的评论中指出的那样,您不必使用 vba,而是使用公式。

以下是一些可帮助您构建正确公式的链接:

如果您无法获取它,请使用您尝试过的内容以及您想要做的更深入的示例来编辑您的第一篇文章。

问候,

As iDevlop pointed out in his/her comment, you don't have to use vba but rather a formula.

Here are a few links to help you in building the right formula:

If you can't get it, please edit your first post with what you tried and a deeper example of what you are trying to do.

Regards,

若相惜即相离 2024-12-02 09:02:11

可以使用用户窗体搜索工作簿工作表之间的匹配单元格。

当双击要搜索的单元格时,用户窗体打开,匹配的单元格可以在用户窗体列表框控件上看到工作表名称和单元格地址。列表框中选定的单元格地址成为活动单元格。

输入图片此处描述

用户表单的 VBA 代码:

Dim Alan2 As Range, Sayfa As Worksheet
ListBox1.ColumnCount = 2
ListBox1.ColumnWidths = "110;40"
For Each Sayfa In ActiveWorkbook.Worksheets
    For Each Alan2 In Sheets(Sayfa.Name).UsedRange
         If Alan2 = ActiveCell.Value Then
             ListBox1.AddItem Sayfa.Name
             ListBox1.List(ListBox1.ListCount - 1, 1) = Alan2.AddressLocal(0, 0)
          End If
    Next Alan2
    Next Sayfa
Label1.Caption = " " & "Found Records: " & ListBox1.ListCount

源代码和示例文件地址

Matching cells between sheets of the workbook can be searched using the userform.

When the cell that to be searched is double-clicked,userform opens and the matching cells can be seen as sheet name and cell address on the userform listbox control.The selected cell addresses in the listbox become active cell.

enter image description here

VBA codes of userform:

Dim Alan2 As Range, Sayfa As Worksheet
ListBox1.ColumnCount = 2
ListBox1.ColumnWidths = "110;40"
For Each Sayfa In ActiveWorkbook.Worksheets
    For Each Alan2 In Sheets(Sayfa.Name).UsedRange
         If Alan2 = ActiveCell.Value Then
             ListBox1.AddItem Sayfa.Name
             ListBox1.List(ListBox1.ListCount - 1, 1) = Alan2.AddressLocal(0, 0)
          End If
    Next Alan2
    Next Sayfa
Label1.Caption = " " & "Found Records: " & ListBox1.ListCount

Source and sample file address

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文