나눔터  
  HOME > 나눔터 > 묻고답하기 > 엑셀
엑셀
엑셀에 대한 질문과 답변을 올려주세요. 단, 취지에 맞지 않는 글은 운영자가 삭제합니다.
 "000 님, 도와주세요", "부탁 드립니다.", "급합니다!" 등과 같이 막연한 제목을 달지 말아주세요.
[필독] 빠르고 정확한 답변을 얻는 16가지 Tip !
[필독] 저작권법 개정에 따른 이용안내
작성자:  

 참서리 (k5953)

추천:  2
파일:     dic_dic_arrayLIst.xls (56.5KB) 조회:  1670
제목:   Dictionary+ArrayyList로 구분하여 처리
     
 
'------------------------------
Sub dic_arrayList()
'------------------------------




    Dim ADic As New Scripting.Dictionary
    Dim BDic As Scripting.Dictionary
    Dim oList As Object
    
    Dim varX As Variant: varX = [A1].CurrentRegion.Value
    Dim vKey As Variant
    Dim vDate As Variant
       
    Application.ScreenUpdating = False
    
       
    '----------------------------------
    For r = 2 To UBound(varX, 1)
    '----------------------------------
        
        ' 장소
        vKey = varX(r, 3)
        
        
        ' 장소가 딕셔녀리에 있으면
        '------------------------------
        If ADic.Exists(vKey) Then
        '------------------------------
        
                    Set BDic = ADic.Item(vKey)
                    vDate = varX(r, 1)
                    
                                                           
                    '------------------------------
                    If BDic.Exists(vDate) Then
                    '------------------------------
                    
                        ' ArrayList에 엾으면 추가
                    
                        If Not BDic.Item(vDate).contains(varX(r, 2)) Then BDic.Item(vDate).Add varX(r, 2)
                    
                    
                    
                    Else
                        
                        ' ArrayList 생성
                        Set oList = CreateObject("System.Collections.ArrayList")
                        ' ArrayyList에 이름 추가
                        oList.Add varX(r, 2)
                        
                        ' dictionary에 arrayList추가
                        BDic.Add vDate, oList
                        
                        
                    '------------------------------
                    End If
                    '------------------------------
    
        Else ' not exist
                        
            
                    Set oList = CreateObject("System.Collections.ArrayList")
                    
                    ' 이름 넣기
                    oList.Add varX(r, 2)
                    
                    Set BDic = New Scripting.Dictionary
                    
                    BDic.Add varX(r, 1), oList
                    
                    ADic.Add vKey, BDic
                    
        
        End If
    
    Next r
    
    
' delete existing sheets
Call delete_shts

Dim shtX As Worksheet
Dim j As Long

'Stop


'-------------------------------------
For Each skey In ADic.Keys
'-------------------------------------


    '시트 생성
    Set shtX = Worksheets.Add(After:=Worksheets(Worksheets.Count))
    shtX.Name = skey
    
    ' 제목 행 입력
    shtX.[A1:C1].Value = Array("날짜", "이름", "장소")
    
    Set BDic = ADic.Item(skey)
    
    j = 2
    
    '---------------------------------------------------
    For Each Key In BDic.Keys
    '---------------------------------------------------
    
        shtX.Cells(j, 1).Value = Key
        shtX.Cells(j, 2).Value = Join(BDic.Item(Key).toarray, ",")
        shtX.Cells(j, 3).Value = skey
        
        j = j + 1
    
    Next Key
        


Next


Worksheets("main").Activate
    
Application.ScreenUpdating = True

MsgBox "Job Done"
    
    
    
End Sub






'---------------------------------
Sub delete_shts()
'---------------------------------

    Dim sht As Worksheet
    
    Application.DisplayAlerts = False
    
    For Each sht In Worksheets
            If sht.Name <> "main" Then sht.Delete
    Next sht
    
    Application.DisplayAlerts = True
    
End Sub
 
[불량 게시물 신고]  
카스답변 고맙습니다. 죄송하지만 서식을 좀 더 수정해서 파일을 올려봅니다.07-19 (14:30)
삭제 ■신고
        
  

작성일 : 2019-07-18(21:57)
최종수정일 : 2019-07-18(21:57)
 


 ◎ 관련글

  제 목   작성자   날짜
자료만들기 카스 2019-07-18
Dictionary+ArrayyList로 구분하여 처리 참서리 2019-07-18
[RE]자료만들기 dew 2019-07-18