跳到主要内容

如何在多个工作表或工作簿中快速搜索值?

作者:孙 最后修改时间:2022-09-13

您是否曾经想过要在Excel中的多个工作表或工作簿中搜索某个值? 本教程介绍了一些不同的方法来解决有关在多个工作表中搜索或在多个工作簿中进行搜索的问题。

使用查找和替换功能在工作簿的多个表中搜索值

使用VBA在文件夹的所有工作簿中搜索值

使用 Kutools for Excel 在多个打开的工作簿中快速搜索值 好主意3


用Excel的 查找和替换 函数,您可以在多张纸上找到某个值。

1.按住要选择多个工作表标签以从中寻找价值 按Ctrl 键并单击工作表中的 工作表标签栏 逐个。 看截图:

多页中的doc搜索值1

2.然后按 Ctrl + F 使之成为可能 查找和替换 窗口,然后在 查找内容 下的文本框 找到最适合您的地方 标签,然后单击 找到所有 按钮列出所有结果。 看截图:

多页中的doc搜索值2


在工作表和工作簿中查找和替换价值

Kutools for Excel的进阶 查找和替换 功能,可以帮助您跨多个工作表和已打开的工作簿查找和替换值。  免费下载
寻找替代
 
Kutools for Excel:拥有300多个便捷的Excel加载项,可以在30天内免费试用。

如果要从文件夹中搜索所有已关闭工作簿中的值,则只能应用VBA来解决它。

1.启用一个新工作簿并选择一个单元格,然后按 Alt + F11键 打开钥匙 Microsoft Visual Basic应用程序 窗口。

2。 点击 插页 > 模块 并将其粘贴到VBA下方的新“模块”窗口中。

VBA:在文件夹的所有工作簿中搜索值。

Sub SearchFolders()
'UpdatebyKutoolsforExcel20200913
    Dim xFso As Object
    Dim xFld As Object
    Dim xStrSearch As String
    Dim xStrPath As String
    Dim xStrFile As String
    Dim xOut As Worksheet
    Dim xWb As Workbook
    Dim xWk As Worksheet
    Dim xRow As Long
    Dim xFound As Range
    Dim xStrAddress As String
    Dim xFileDialog As FileDialog
    Dim xUpdate As Boolean
    Dim xCount As Long
    Dim xAWB As Workbook
    Dim xAWBStrPath As String
    Dim xBol As Boolean
    Set xAWB = ActiveWorkbook
    xAWBStrPath = xAWB.Path & "\" & xAWB.Name
    On Error GoTo ErrHandler
    Set xFileDialog = Application.FileDialog(msoFileDialogFolderPicker)
    xFileDialog.AllowMultiSelect = False
    xFileDialog.Title = "Select a forlder"
    If xFileDialog.Show = -1 Then
        xStrPath = xFileDialog.SelectedItems(1)
    End If
    If xStrPath = "" Then Exit Sub
    xStrSearch = "KTE"
    xUpdate = Application.ScreenUpdating
    Application.ScreenUpdating = False
    Set xOut = Worksheets.Add
    xRow = 1
    With xOut
        .Cells(xRow, 1) = "Workbook"
        .Cells(xRow, 2) = "Worksheet"
        .Cells(xRow, 3) = "Cell"
        .Cells(xRow, 4) = "Text in Cell"
        Set xFso = CreateObject("Scripting.FileSystemObject")
        Set xFld = xFso.GetFolder(xStrPath)
        xStrFile = Dir(xStrPath & "\*.xls*")
        Do While xStrFile <> ""
            xBol = False
            If (xStrPath & "\" & xStrFile) = xAWBStrPath Then
                xBol = True
                Set xWb = xAWB
            Else
                Set xWb = Workbooks.Open(Filename:=xStrPath & "\" & xStrFile, UpdateLinks:=0, ReadOnly:=True, AddToMRU:=False)
            End If
            For Each xWk In xWb.Worksheets
                If xBol And (xWk.Name = .Name) Then
                Else
                Set xFound = xWk.UsedRange.Find(xStrSearch)
                If Not xFound Is Nothing Then
                    xStrAddress = xFound.Address
                End If
                Do
                    If xFound Is Nothing Then
                        Exit Do
                    Else
                        xCount = xCount + 1
                        xRow = xRow + 1
                        .Cells(xRow, 1) = xWb.Name
                        .Cells(xRow, 2) = xWk.Name
                        .Cells(xRow, 3) = xFound.Address
                        .Cells(xRow, 4) = xFound.Value
                    End If
                    Set xFound = xWk.Cells.FindNext(After:=xFound)
                Loop While xStrAddress <> xFound.Address
                End If
            Next
            If Not xBol Then
            xWb.Close (False)
            End If
            xStrFile = Dir
        Loop
        .Columns("A:D").EntireColumn.AutoFit
    End With
    MsgBox xCount & " cells have been found", , "Kutools for Excel"
ExitHandler:
    Set xOut = Nothing
    Set xWk = Nothing
    Set xWb = Nothing
    Set xFld = Nothing
    Set xFso = Nothing
    Application.ScreenUpdating = xUpdate
    Exit Sub
ErrHandler:
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
End Sub

3.然后按 F5 键或 运行 按钮执行此VBA, 选择一个文件夹 弹出对话框,提醒您选择要从中搜索值的文件夹。 看截图:

多页中的doc搜索值3

4.然后单击 OK 弹出另一个对话框,提醒您已找到单元格的数量。 看截图:

多页中的doc搜索值4

5。 点击 OK关闭 它,所有找到的单元格都在当前工作表中列出,并带有相应的信息。

多页中的doc搜索值5

提示: 在以上VBA中,您搜索值 “ KTE”,您可以更改 “ KTE” 从这个 xStrSearch =“韩国电信" 您需要的另一个值。


如果您只想在多个打开的工作簿中搜索值,则可以使用 Excel 的 Kutools'先进的 查找和替换 效用。

Kutools for Excel, 与超过 300 方便的功能,使您的工作更加轻松。 

免费安装 Kutools for Excel,请执行以下操作:

1.在其中一个打开的工作簿中,单击 库工具 > 旅游导航 ,然后单击 查找和替换 按键 doc查找按钮查找和替换 窗格。 看截图:

多页中的doc搜索值6

2。 然后点击 找到最适合您的地方 标签,然后在 查找内容 文本框,然后选择 所有工作簿 来自 下拉列表,然后单击 找到所有 列出所有找到的单元格。 看截图:
doc kutools查找替换2

提示:

Kutools for Excel的进阶 查找和替换 实用程序,您可以跨多个工作簿,所有工作簿,活动工作簿,活动工作表或选定内容搜索和替换选定工作表中的值。
doc kutools查找替换3


相关文章:

最佳办公生产力工具

🤖 Kutools 人工智能助手:基于以下内容彻底改变数据分析: 智能执行   |  生成代码  |  创建自定义公式  |  分析数据并生成图表  |  调用 Kutools 函数...
热门特色: 查找、突出显示或识别重复项   |  删除空白行   |  合并列或单元格而不丢失数据   |   不使用公式进行四舍五入 ...
超级查询: 多条件VLookup    多值VLookup  |   跨多个工作表的 VLookup   |   模糊查询 ....
高级下拉列表: 快速创建下拉列表   |  依赖下拉列表   |  多选下拉列表 ....
列管理器: 添加特定数量的列  |  移动列  |  切换隐藏列的可见性状态  |  比较范围和列 ...
特色功能: 网格焦点   |  设计图   |   大方程式酒吧    工作簿和工作表管理器   |  资源库 (自动文本)   |  日期选择器   |  合并工作表   |  加密/解密单元格    按列表发送电子邮件   |  超级筛选   |   特殊过滤器 (过滤粗体/斜体/删除线...)...
前 15 个工具集12 文本 工具 (添加文本, 删除字符,...)   |   50+ 图表 类型 (甘特图,...)   |   40+ 实用 公式 (根据生日计算年龄,...)   |   19 插入 工具 (插入二维码, 从路径插入图片,...)   |   12 转化 工具 (小写金额转大写, 货币兑换,...)   |   7 合并与拆分 工具 (高级组合行, 分裂细胞,...)   |   ... 和更多

使用 Kutools for Excel 增强您的 Excel 技能,体验前所未有的效率。 Kutools for Excel 提供了 300 多种高级功能来提高生产力并节省时间。  单击此处获取您最需要的功能...

描述


Office Tab 为 Office 带来选项卡式界面,让您的工作更加轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!
Comments (18)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
program stops here:

Set xWb = Workbooks.Open(Filename:=xStrPath & "\" & xStrFile, UpdateLinks:=0, ReadOnly:=True, AddToMRU:=False)
This comment was minimized by the moderator on the site
Hi, Mike, I have update the VBA in the article, please try again. If there is any problem, please let me know, thank you.
This comment was minimized by the moderator on the site
HI in my case worksheet with more than 1 Lakhs record, scripts failed.
This comment was minimized by the moderator on the site
Hi, Dhireesh, VBA code has its own limitation. You could try Kutools for Excel's Fiind and Replace, but it may run slowly, please be patience, and had better save the workbooks before.
This comment was minimized by the moderator on the site
How do i create hyperlink under column C for all cell values in the same code?
This comment was minimized by the moderator on the site
como generar códigos qr
This comment was minimized by the moderator on the site
Awesome this works perfect,
Could you help me, I would like to create an hyperlink to each cell where the value was found.

Thanks in advance
This comment was minimized by the moderator on the site
me too I would like! :)
This comment was minimized by the moderator on the site
Perfect for what I need except for the fact that it creates a new sheet every search. How would I modify the code to use a single sheet for each search instead of creating a new one? Thanks, James
This comment was minimized by the moderator on the site
Your code works great, I look for a code that finds two texts in excel files, do you know how is it possible?
This comment was minimized by the moderator on the site
Sorry, I have no idea on this problem, you can go to our forum https://www.extendoffice.com/forum.html to carry on the problem, maybe someone know the answer.
This comment was minimized by the moderator on the site
How can I add another column and bring the value that is always 3 columns to the right on the value found?
This comment was minimized by the moderator on the site
Did you ever figure this out? I need that as well.
This comment was minimized by the moderator on the site
Sorry I cannot help you, you can go to out forum https://www.extendoffice.com/forum.html to carry on the question, maybe someone can help you.
This comment was minimized by the moderator on the site
Thanks. It helped me a lot =)
This comment was minimized by the moderator on the site
This is what i want it to return "Site Instruction" which is allocated to all Text in Cell
Workbook Worksheet Cell Text in Cell Site Instruction
Shift report Emicc 01-10-17.xlsx Sheet1 $D$20 CMS install 1773
Shift report Emicc 01-10-17.xlsx Sheet1 $D$21 CMS install 1763
Shift report Emicc 01-10-17.xlsx Sheet1 $D$24 CMS install 1551
There are no comments posted here yet
Load More
Leave your comments
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations