簡體   English   中英

在多個Excel工作簿中搜索同一單元格和同一工作表中的值

[英]Searching multiple Excel workbooks for value in same cell and same sheet

我正在一項新工作中學習VBA,並被分配了一個項目,該項目涉及檢查大約100個工作簿中的值。 該值包含在100個工作簿中每一個工作簿中具有相同名稱的工作表的相同單元格(I12)中。 是否可以使用SQL將值從每個工作簿中的一個單元格傳遞到變量,以便我可以比較它們? 我當前的代碼打開了每個工作簿以比較這些值,這雖然有效,但是很費時。

如果只是一個Cell,則可能要嘗試ExecuteExcel4Macro
就像是:

Sub Test()
    Dim fexcel
    Dim fpath As String, fval As String, aval
    fpath = "C:\Users\User.Name\FolderName\" '~~> change to suit
    fexcel = Dir(fpath, vbNormal)
    Do While fexcel <> ""
        '~~> Sheet1 should be the sheet name, R12C9 is I12 in R1C1 notation
        fval = "'" & fpath & "[" & fexcel & "]Sheet1'!R12C9"
        aval = ExecuteExcel4Macro(fval)
        '~~> Do your comparison here or dump information in an array
        fexcel = Dir
    Loop
End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM