我試圖將多個工作表中的數據合併爲一個,使用描述的方法here。Excel VBA複製/粘貼錯誤
的差異我只想從複製因此每個文件數據的單一專欄中,我已經修改了我的代碼這樣的:
With wsMaster
erow = .Range("B" & .Rows.Count).End(xlUp).Row 'get the last row in column B
'~~> Copy from the file you opened
wsTemp.Range("A2:A" & .Rows.Count).Copy 'copy data in column A starting at row 2
'to however long the data runs for
'~~> Paste on your master sheet below last used row in column B
.Range("B" & erow).Offset(1, 0).PasteSpecial xlPasteValues
End With
這適用於第一次迭代(它複製的第一個源文件正確),但當它到達第二個源文件時,它會拋出一個錯誤「運行時錯誤'1004':PasteSpecial方法或Range類失敗」。
當處於調試模式時,我嘗試手動點擊並Ctrl + V複製的數據,它表示範圍的大小/形狀不匹配。但是,如果我點擊第2行或以上的任何單元格,它會粘貼在宏中複製的數據,而不會抱怨。
任何想法?
這個工作。謝謝! –