';将多个工作表中的数据附加到单个工作表宏中
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了';将多个工作表中的数据附加到单个工作表宏中相关的知识,希望对你有一定的参考价值。
'Append data from multiple worksheet to single worksheet macro
'Append data from multiple worksheet to single worksheet macro Sub CombineData() Dim wksFirst As Worksheet Dim wksLast As Worksheet Dim wksDest As Worksheet Dim strFirstSht As String Dim strLastSht As String Dim strDestSht As String Dim NextRow As Long Dim i As Long strFirstSht = "Sheet1" 'change the name of the first sheet accordingly strLastSht = "Sheet2" 'change the name of the last sheet accordingly strDestSht = "Combined Data" 'change the name of the destination sheet accordingly On Error Resume Next Set wksFirst = Worksheets(strFirstSht) If wksFirst Is Nothing Then MsgBox strFirstSht & " does not exist...", vbInformation Exit Sub Else Set wksLast = Worksheets(strLastSht) If wksLast Is Nothing Then MsgBox strLastSht & " does not exist...", vbInformation Exit Sub End If End If On Error GoTo 0 Application.ScreenUpdating = False On Error Resume Next Application.DisplayAlerts = False Worksheets(strDestSht).Delete Application.DisplayAlerts = True On Error GoTo 0 Set wksDest = Worksheets.add(Worksheets(1)) wksDest.Name = strDestSht For i = wksFirst.Index To wksLast.Index Worksheets(i).Range("A1:H89").Copy With wksDest NextRow = .Cells(.Rows.count, "A").End(xlUp).row + 1 With .Cells(NextRow, "A") .PasteSpecial Paste:=8 'column width for Excel 2000 and later .PasteSpecial Paste:=xlPasteValues .PasteSpecial Paste:=xlPasteFormats End With End With Next i wksDest.Cells(1).Select Application.CutCopyMode = False Application.ScreenUpdating = True End Sub
以上是关于';将多个工作表中的数据附加到单个工作表宏中的主要内容,如果未能解决你的问题,请参考以下文章
如何将单个工作表中的多行(在 excel 中)转换为多个 CSV 文件
将许多 Excel 工作簿和工作表中的数据导入单个工作簿/表格
在 R 中拆分大型数据框并输出到单个 Excel 工作簿中的单独工作表中