跳到主要內容

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

您是否曾經想過要在Excel中的多個工作表或工作簿中搜索某個值? 本教程介紹了一些不同的方法來解決有關在多個工作表中搜索或在多個工作簿中進行搜索的問題。

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

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

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


用Excel的 查找和替換 函數,您可以在多張紙上找到某個值。

1.按住要選擇多個工作表標籤以從中尋找價值 按Ctrl 鍵並單擊工作表中的 工作表標籤欄 逐個。 看截圖:

多頁中的doc搜索值1

2.然後按 Ctrl + F 使之成為可能 查找和替換 窗口,然後在 查找內容 下的文本框 發現 選項卡,然後單擊 找到所有 按鈕列出所有結果。 看截圖:

多頁中的doc搜索值2


在工作表和工作簿中查找和替換價值

Excel的Kutools的進階 查找和替換 功能,可以幫助您跨多個工作表和已打開的工作簿查找和替換值。  免費下載
尋找替代
 
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 =“KTE" 您需要的另一個值。


如果您只想在多個打開的工作簿中搜索值,則可以使用 Kutools for Excel'先進的 查找和替換 效用。

Excel的Kutools, 與以上 300 方便的功能,使您的工作更加輕鬆。 

免費安裝 Kutools for Excel,請執行以下操作:

1.在其中一個打開的工作簿中,單擊 庫工具 > 導航,然後單擊 查找和替換 按鍵 doc查找按鈕查找和替換 窗格。 看截圖:

多頁中的doc搜索值6

2。 然後點擊 發現 標籤,然後在 查找內容 文本框,然後選擇 所有工作簿 來自 下拉列表,然後單擊 找到所有 列出所有找到的單元格。 看截圖:
doc kutools查找替換2

小提示:

這款獨特的敏感免洗唇膜採用 Moisture WrapTM 技術和 Berry Mix ComplexTM 成分, Excel的Kutools的進階 查找和替換 實用程序,您可以跨多個工作簿,所有工作簿,活動工作簿,活動工作表或選定內容搜索和替換選定工作表中的值。
doc kutools查找替換3


相關文章:

最佳辦公生產力工具

🤖 Kutools 人工智慧助手:基於以下內容徹底改變數據分析: 智慧執行   |  生成代碼  |  建立自訂公式  |  分析數據並產生圖表  |  呼叫 Kutools 函數...
熱門特色: 尋找、突出顯示或識別重複項   |  刪除空白行   |  合併列或儲存格而不遺失數據   |   沒有公式的回合 ...
超級查詢: 多條件VLookup    多值VLookup  |   跨多個工作表的 VLookup   |   模糊查詢 ....
高級下拉列表: 快速建立下拉列表   |  依賴下拉列表   |  多選下拉列表 ....
欄目經理: 新增特定數量的列  |  移動列  |  切換隱藏列的可見性狀態  |  比較範圍和列 ...
特色功能: 網格焦點   |  設計圖   |   大方程式酒吧    工作簿和工作表管理器   |  資源庫 (自動文字)   |  日期選擇器   |  合併工作表   |  加密/解密單元格    按清單發送電子郵件   |  超級濾鏡   |   特殊過濾器 (過濾粗體/斜體/刪除線...)...
前 15 個工具集12 文本 工具 (添加文本, 刪除字符,...)   |   50+ 圖表 類型 (甘特圖,...)   |   40+ 實用 公式 (根據生日計算年齡,...)   |   19 插入 工具 (插入二維碼, 從路徑插入圖片,...)   |   12 轉化 工具 (數字到單詞, 貨幣兌換,...)   |   7 合併與拆分 工具 (高級合併行, 分裂細胞,...)   |   ... 和更多

使用 Kutools for Excel 增強您的 Excel 技能,體驗前所未有的效率。 Kutools for Excel 提供了 300 多種進階功能來提高生產力並節省時間。  點擊此處獲取您最需要的功能...

產品描述


Office選項卡為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
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations