我的代码当前将我复制的所有文件粘贴到一个单独的列中。
我需要它去为每个新文件,而不是一行不同的列。
即file1到col 1 file2到col 2等
它会涉及到将.row更改为columns或一个新的命令吗?
这里的代码
Option Explicit
Sub CopyDataFromDump()
Dim SourceFolder As String
Dim nSourceFolder As String
Dim Filename As String
Dim Wb As Workbook
Dim CopyFromSheet As Worksheet
Dim PasteToSheet As Worksheet
Dim LastRow As Long
SourceFolder = "" ' folder path where your workbooks are located
Dim ws As Worksheet
Dim oFSO As Variant
Dim oFolder As Variant
Dim oFile As File
Dim MyFSO As FileSystemObject
Set MyFSO = New FileSystemObject
Set oFolder = MyFSO.GetFolder(SourceFolder)
For Each oFile In oFolder.Files
Set Wb = Workbooks.Open(oFile, , Format:=5) 'open each workbook in the folder
Set CopyFromSheet = Wb.Sheets(1) ' sheet from where you want to copy data
Set PasteToSheet = ThisWorkbook.Sheets(1) ' sheet from where you want to paste data
CopyFromSheet.UsedRange.Copy ' Copy data from the specified sheet in the opened workbook
LastRow = PasteToSheet.Cells(PasteToSheet.Row.Count, "A").End(xlUp).Row + 1 ' Find the last row in the paste sheet
PasteToSheet.Cells(LastRow, 1).PasteSpecial xlPasteValues ' Paste data into the destination sheet in the active workbook
Wb.Close False ' Close the opened workbook
Next oFile
End Sub
字符串
我试过Active.sheets.cell。
1条答案
按热度按时间vmpqdwk31#
假设
UsedRange
在第1行中没有空单元格:字符串