[英]copy and paste specific cells from EXCEL into specific SPSS cells
[英]Copy and paste not empty cells from a specific range
我从来没有不使用 VBA 脚本或宏。
但是我需要将很多excel文件复制粘贴到一个文件中。 所以我想知道如何实现以下(或朝哪个方向发展):
我需要复制一个包含 x 行和 y 列的表格,但有很多空行。 并且合并了很多行。 我需要将其复制到另一个文件并取消合并行并将内容复制到所有合并的列。
有多个这样的文件,需要进入一个文件。 每个文件都有不同数量的纸张。
如果有的话,我可以创建一个宏来仅复制和粘贴非空列并取消合并合并的列并在所有合并的行之间具有相同的数据?
这是部分答案,不涉及单个工作表的处理。 它确实为您提供了一个框架。
Sub Process_Workbooks()
'Process a Collection of workbooks
Dim arrPathandFile, FilePointer As Long
Dim strPathAndFile As String
Dim bkSource As Workbook, shInput As Worksheet
Dim bkDestination As Workbook, shResult As Worksheet
Dim myPath, PathandFile As String
arrPathandFile = Application.GetOpenFilename("Audit Files (*.xls*), *.xlsx, All Files (*.*), *.*", , "Select Workbooks to process", "", True)
' user cancels file selection
If Not IsArray(arrPathandFile) Then Exit Sub
'Create a place to put the results
Set bkDestination = Workbooks.Add
'For each file in the collectin
For FilePointer = 1 To UBound(arrPathandFile)
strPathAndFile = arrPathandFile(FilePointer)
'Open the workbook
Set bkSource = Workbooks.Open(strPathAndFile)
'process each worksheet
For Each shInput In bkSource.Sheets
Set shResult = bkDestination.Sheets.Add
shResult.Name = shInput.Name & "(" & FilePointer & ")"
'figure out the source range to copy
shInput.Range("A1:Z900").Copy Destination:=shResult.Range("A1")
'now do stuff to the sheet in the destination.
Call Do_Stuff_To_sheets(shInput)
'repeat for each sheet in the workbook
Next shInput
bkSource.Close
'repeat for each workbook selected
Next FilePointer
'save the results
bkDestination.SaveAs myPath & "NewFilename.xlsx"
End Sub
Private Sub Do_Stuff_To_sheets(mySheet As Worksheet)
'process each sheet to unmerge and defrag columns
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.