2012-12-30 2 views
0

하나의 요약 시트에 여러 워크 시트를 병합하려고합니다.
각 워크 시트의 이름은 'Table #number'입니다 (예 : Table 1, Table 2 등). 각 시트의 레이아웃은 동일합니다. 데이터 범위는 열 A1 : N13입니다.
이 기능은 작동하지 않습니다 : =SUM('Table 1':'Table 25'!$A$1:$N$13).
VBA을 사용하여 데이터를 병합하는 방법은 무엇입니까?하나에 여러 워크 시트를 병합

enter image description here

+2

여러 워크 시트를 하나의 h에 병합 그래서 많은 시간을 다룹니다. 너 찾았 니? 그래서 검색을 권장하고 직접 시도하고 오류 메시지 (예 :있는 경우)로 시도한 코드를 게시 한 다음 거기에서 가져옵니다. :) –

답변

0

이 단순화 된 예입니다

Option Explicit 

Sub amalgamateData() 

'initialise result variable 
Dim myResult As Double 
myResult = 0 

'loop through sheets to get the sum 
Dim wks As Excel.Worksheet 'loop control variable 
For Each wks In Excel.ThisWorkbook.Worksheets 
    If Left(wks.Name, 5) = "Table" Then ' only the "Table" sheets 
     With wks 
      Dim rngTarget As Range 
      myResult = myResult + Excel.Application.WorksheetFunction.Sum(.Range("A1:N13")) 
     End With 
    End If 
Next 

'add result to sheet "Result" 
Excel.ThisWorkbook.Sheets("Result").Range("A1") = myResult 

End Sub 

내 출발점 싯다 르트 나라 얀의 사우드으로이 SO Post: how-to-merge-data-from-multiple-sheets

이었다 -이 SO HERE IS A SEARCH FOR YOU ... CHECK OUT WHAT IS IN THE BOX IN THE TOP RIGHT OF THE SCREEN

0
Sub MergeSheet() 

'Declaring the Variables 
Dim LastRow, ShtCnt As Integer 
Dim ShtName As String 
Dim NewSht As Worksheet 

'Assinging a Sheet Name by UserInput 
ShtName: 
ShtName = InputBox("Enter the Sheet Name you want to create", "Merge Sheet", "Master Sheet") 

'Count of Total Worksheet in the present workbook 
ShtCnt = Sheets.Count 

'Using For Loop check if the worksheet exists 
For i = 1 To ShtCnt 
If Sheets(i).Name = ShtName Then 
MsgBox "Sheet already Exists", , "Merge Sheet" 
GoTo ShtName 
End If 
Next i 

'Create a New Sheet 
Worksheets.Add.Name = ShtName 

'Assigning NewSht as Current Sheet 
Set NewSht = ActiveSheet 

'Moving Worksheet to the beginning of this workbook 
NewSht.Move before:=Worksheets(1) 

'Copying all the data to the New Sheet Using For Loop 
For i = 2 To ShtCnt + 1 

'If i=2 Then copy all the data from the second sheet including header. 
If i = 2 Then 
Sheets(i).UsedRange.Copy NewSht.Cells(1, 1) 
Else 

'If i is grater than 2 then copy all the data excluding Header(1st Row). 
Sheets(i).UsedRange.Offset(1, 0).Resize(Sheets(i).UsedRange.Rows.Count - 1, Sheets(i).UsedRange.Columns.Count).Copy NewSht.Cells(LastRow + 1, 1) 
End If 
LastRow = NewSht.Cells.SpecialCells(xlCellTypeLastCell).Row 
Next i 

'Displaying the Message after copying data successfully 
MsgBox "Data has been copied to " & ShtName, , "Merge Sheet" 

End Sub 
에 당신을 위해 참고 문헌의 부하
관련 문제