Skip Navigation Links.
Expand VBAVBA
엑셀프로그래밍이 필요한 이유
Expand ExcelExcel
Expand External LibraryExternal Library
Expand SolutionSolution
Expand EssayEssay

Excel & VBA---Brain Training


  • 01

각각의 대리점의 정보가 각각의 시트로 여러장이 구성되어 있다, 통합하기

아래의 그림과 같이 가상의 데이타시트를 만드는 것 부터 해보자
1)3장의 시트에 만든다
2)각장의 시트는 상품명과 1,2,3,4분기의 열머리가 있고
3)상품명은 알파벳문자로 만드는데 중복이 되지 않아야 할 것이고
4)숫자는 난수로 만드는데 100자리는 모두 0으로 처리하게 만든다
5)상품행은 15개 이하로 한다
6)시트명은 [Sheet_A],[Sheet_B]와 같이 A,B,C로 한다



위의 것을 만들려면 아래의 코드를 실행하면 된다

Sub createSampleData() Dim iSheet As Integer Dim iRow As Integer Dim sShtName As String Dim rCurrent As Range Dim sProduct As String Dim sSheet() As String On Error Resume Next For iSheet = 1 To 3 With Worksheets.Add sShtName = "Sheet_" & Choose(iSheet, "A", "B", "C") Application.DisplayAlerts = False Worksheets(sShtName).Delete Application.DisplayAlerts = True .Name = sShtName With .Range("A1") .Resize(, 5) = Array("상품", "1분기", "2분기", "3분기", "분기") For iRow = 1 To Int(Rnd() * 10) + 5 With .Offset(iRow) Set rCurrent = .Cells(1) GoTo NO_DUPE BACK: With .Offset(-1, 1).Cells(2).Resize(, 4) .Formula = "=ROUND(INT(RAND()*200000)+50000,-2)" .Value = .Value End With End With Next End With ' 정렬하기 Dim rData As Range Set rData = .UsedRange rData.Sort rData.Cells(1), xlAscending, , , , , , xlYes End With Next Exit Sub NO_DUPE: Do sProduct = Chr(Int(Rnd() * 26) + 65) Loop While Application.CountIf(Range(rCurrent.EntireColumn.Cells(2), rCurrent), sProduct) > 0 rCurrent = sProduct GoTo BACK End Sub

위의 것을 아래의 그림과 같이 통합하기가 문제



데이타의 통합메뉴를 실행시키는 것을 자동화하는 작업
코드 몇줄 이면 된다

***[LOG-IN]***

  • 01