0

我正在尝试将多个工作簿加载到同一张工作表中,这些工作簿都将包含一个共同的列标题。加载多个工作簿后,我想搜索我想要的行并将其粘贴到新工作表上。

到目前为止,我已经完成了搜索和粘贴部分,但是需要加载多个工作簿的部分非常困难,有人可以帮我解决这个问题吗?谢谢。

Sub SearchRowAndCopy()
Dim strSearch 
strSearch = Application.InputBox("Please enter the search string")
x = 2
Do While Cells(x, 1) <> ""
If Cells(x, 2) Like "*" & strSearch & "*" Then
Worksheets("Sheet1").Rows(x).Copy
Worksheets("Sheet2").Activate
erow = Sheet2.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ActiveSheet.Paste Destination:=Worksheets("Sheet2").Rows(erow)
End If
Worksheets("Sheet1").Activate
x = x + 1
Loop
End Sub
4

1 回答 1

1
Sub GetFiles()
    Dim fPath As String
    Dim sFile As String
    Dim wb As Workbook

    fPath = "D:\Analysis\"

    sFile = Dir(fPath & "*.xls*")

    Do While Len(sFile) > 0
        Debug.Print fPath & sFile
        Set wb = Workbooks.Open(Filename:=sFile, ReadOnly:=True)
        '...
        'do your copying
        '...
        wb.Close False
        sFile = Dir
    Loop
End Sub
于 2013-10-29T03:09:06.960 回答