PROGRAMMING WORKSHOP

Data Table | 워크시트데이타도구..통합..Consolidation

엑셀의 데이타메뉴에 통합(Consolidation)이라는 것이 있다
여러장의 시트에 같은 형식의 테이블들이 있을때 모든 시트의 내용을
집계 하는 도구이다..
그런 것을 해보도록 하자
아래의 코드를 실행하면 연습용테이블이 10장의 시트에 만들어진다

Sub consolidtationPraticingCode()
Dim iSht As Integer
Dim iTbl As Integer
Dim iRow As Integer
Dim iCol As Integer
Dim sRow As String
Dim sCol As String
Dim shtX As Worksheet
Dim bWritten As Boolean

Dim iX As Integer, iY As Integer
Dim rX As Range
Const sShtName As String = "통합연습"
sRow = "ABCDEFGHIJKLMNOPQRSTIVWXYZ"
sCol = "백두금강한라지리소백속리가야계룡관악내장덕유가리두타마니명지"
On Error Resume Next

Application.DisplayAlerts = False
For Each shtX In Worksheets
    If InStr(shtX.Name, sShtName) > 0 Then
        shtX.Delete
    End If
Next
Application.DisplayAlerts = True
Application.EnableEvents = False
For iSht = 1 To 10
    iRow = Int(Rnd() * 5) + 5
    iCol = Int(Rnd() * 5) + 5
    With Worksheets.Add
    .Name = sShtName & iSht
    bWritten = False
    With .Cells(Int(Rnd() * 3) + 1, Int(Rnd() * 3) + 1)
        For iX = 1 To iRow
            For iY = 1 To iCol
                Select Case True
                    Case iY = 1 And iX = 1 And Not bWritten
                       fillRowHead .Cells(iX).Resize(, iCol), sCol
                       fillRowHead .Cells(iX).Resize(iRow), sRow
                       bWritten = True
                    Case iX > 1 And iY > 1
                        .Cells(iX, iY) = Int(Rnd() * 1000) + 500
                End Select
            Next
        Next
        With .CurrentRegion
            .Font.Size = 10
            .Font.Name = "맑은 고딕"
        End With
    End With
    End With
Next
Application.EnableEvents = True

End Sub

Function fillRowHead(rTarget As Range, sData As String)
Dim rX As Range
Dim iX As Integer
Dim sLabel As String
Dim iLen As Integer
On Error Resume Next
If Asc(Mid(sData, 1, 1)) >= 65 And Asc(Mid(sData, 1, 1)) <= 90 Then
    iLen = 1
Else
    iLen = 2
End If
Randomize
For Each rX In rTarget.Cells
    If iX > 0 Then
        Do
            Dim iRandom As Integer
            iRandom = Int(Rnd * 15) + 1
            sLabel = Mid(sData, IIf(iLen = 2, Application.Odd(iRandom), iRandom), iLen)
        Loop While Not rTarget.Find(sLabel) Is Nothing
        rX = sLabel
    End If
    iX = iX + 1
Next
End Function

어떤 형식의 테이블이 만들어지는지는 위의 것을 실행하시고
이렇게 각각의 시트에 분산된 같은 형식의 테이블의
내용을 분석하여 보시기 바란다
손작업으로 통합, 피봇두가지 작업이 가능할 것이다
이것을 VBA로 처리하는 작업을 몇개의 화일로 해보자

STEP_1 ---------------------------------

보고서 시트를 만들어 보자
보고서 테이블의 행머리와 열머리를 만들어야 한다
중복되지 않아야 하고
이왕이면 정렬도 되어야 한다
열머리도 정렬하고, 행머리도 정렬하고,
정렬은 배열로 정렬을 할 수도 있겠지만 엑셀의 정렬을 사용하고
일반적으로 행방향정렬을 하지만, 여기에서는 열방향정렬이 필요하겠다
그리고 중복되지 않는 열머리,행머리정보를 수집하기에 집합체개체의 활용

***[LOG-IN]***