从多个Excel文件复制数据

时间:2018-05-29 05:45:02

标签: excel-vba vba excel

我有一个包含155个Excel文件的文件夹。我必须将所有155个Excel文件中的F行复制到一个常用工作表中。使用宏

可以做到这一点

由于 拉维〜

1 个答案:

答案 0 :(得分:0)

您是说F列吗?怎么样?

Sub LoopThroughDirectory()
Dim MyFile As String
Dim Filepath As String
Dim count as Integer
Filepath = "D:\DATA\"
MyFile = Dir(Filepath)
count = 1
Application.ScreenUpdating = False

While MyFile <> ""
    If MyFile = "master.xlsm" Then Exit Sub
    Workbooks.Open (Filepath & MyFile)
    Workbooks(MyFile).sheets("Sheet1").Range("F1:F100").Copy thisworkbook.sheets("Sheet1").Cells(3, count)
    Workbooks(MyFile).Close
    count = count + 1
    MyFile = Dir
Loop

Application.ScreenUpdating = True
End Sub