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

 참서리 (k5953)

추천:  2
파일:     template_sheet_1.xlsm (31.6KB) 조회:  1619
제목:   [RE]VBA고수님들 도와주세요
     
  '----------------------------- 
Sub btn_run_Click()
'----------------------------- 

    Application.ScreenUpdating = False
    
    Dim shtX  As Worksheet:
    
    '기존 시트 삭제
    Application.DisplayAlerts = False
    For Each shtX In Worksheets
        If shtX.Name <> "main" And shtX.Name <> "기타영수증" Then shtX.Delete
    Next shtX
    Application.DisplayAlerts = True
    
    ' data sheet
    Set shtX = Worksheets("main")
    ' template sheet
    Dim shtZ As Worksheet: Set shtZ = Worksheets("기타영수증")
    
    ' template sheet visible
    shtZ.Visible = xlSheetVisible
    '-----------------------------------
    
    Dim shtY As Worksheet
    
    'raw data
    Dim rngX As Range: Set rngX = shtX.Range("B19").CurrentRegion
    Dim rngRow As Range
    
    ' filtering-no data
    If rngX.Rows.Count = 1 Then MsgBox "No Data": Exit Sub
    
    
    For r = 2 To rngX.Rows.Count
    
        ' template sheet copy
       shtZ.Copy After:=Worksheets(Worksheets.Count)
       
       Set shtY = Worksheets(Worksheets.Count)
       
        ' data matching
        Set rngRow = rngX.Rows.Item(r)
        shtY.Name = rngRow.Cells(2).Value & Replace(rngRow.Cells(1).Value, "-", "") & rngRow.Cells(9).Value
        '이름
        shtY.[E6].Value = rngRow.Cells(9).Value
        'Flight
        shtY.[K6].Value = rngRow.Cells(7).Value
         '차량
        shtY.[E7].Value = rngRow.Cells(2).Value
         '예약상품
        shtY.[E8].Value = rngRow.Cells(4).Value
          'Date
        shtY.[E9].Value = rngRow.Cells(1).Text & " " & rngRow.Cells(6).Text
          'Pax
        shtY.[E10].Value = rngRow.Cells(8).Value
         'Remark
        shtY.[E11].Value = rngRow.Cells(11).Value
        
    
    Next
    
    shtZ.Visible = xlSheetVeryHidden
    shtX.Activate
           
    Application.ScreenUpdating = True

End Sub


'----------------------------- 
Sub btn_print()
'----------------------------- 
 
    Application.ScreenUpdating = False
    
    Dim shtX  As Worksheet, shtY As Worksheet
    '기존 시트 삭제
    Application.DisplayAlerts = False
    For Each shtX In Worksheets
        If shtX.Name <> "main" And shtX.Name <> "기타영수증" Then shtX.Delete
    Next shtX
    Application.DisplayAlerts = True
    ' data sheet
    Set shtX = Worksheets("main")
    ' template sheet
    Set shtY = Worksheets("기타영수증")
    ' template sheet visible
    shtY.Visible = xlSheetVisible
    

    'raw data
    Dim rngX As Range: Set rngX = shtX.Range("B19").CurrentRegion
    Dim rngRow As Range

    For r = 2 To rngX.Rows.Count

        Set rngRow = rngX.Rows.Item(r)
       
        '이름
        shtY.[E6].Value = rngRow.Cells(9).Value
        'Flight
        shtY.[K6].Value = rngRow.Cells(7).Value
         '차량
        shtY.[E7].Value = rngRow.Cells(2).Value
         '예약상품
        shtY.[E8].Value = rngRow.Cells(4).Value
          'Date
        shtY.[E9].Value = rngRow.Cells(1).Text & " " & rngRow.Cells(6).Text
          'Pax
        shtY.[E10].Value = rngRow.Cells(8).Value
         'Remark
        shtY.[E11].Value = rngRow.Cells(11).Value
        
        '인쇄
        shtY.PrintOut
    Next
    
    shtY.Visible = xlSheetVeryHidden
    shtX.Activate
           
    Application.ScreenUpdating = True

End Sub

'---------------------------------------
Sub btn_print_pdf()
'---------------------------------------

    Application.ScreenUpdating = False
    
    Dim shtX  As Worksheet, shtY As Worksheet
    '기존 시트 삭제
    Application.DisplayAlerts = False
    For Each shtX In Worksheets
        If shtX.Name <> "main" And shtX.Name <> "기타영수증" Then shtX.Delete
    Next shtX
    Application.DisplayAlerts = True
    ' data sheet
    Set shtX = Worksheets("main")
    ' template sheet
    Set shtY = Worksheets("기타영수증")
    ' template visible
    shtY.Visible = xlSheetVisible
    

    'raw data
    Dim rngX As Range: Set rngX = shtX.Range("B19").CurrentRegion
    Dim rngRow As Range
    
    'make folder
    '-----------------
    Dim sFolder As String: sFolder = "D:\pdf_sample"
    If Dir(sFolder, vbDirectory) = "" Then MkDir sFolder
    
    Dim sFile As String

    For r = 2 To rngX.Rows.Count

        Set rngRow = rngX.Rows.Item(r)
      
        
        '이름
        shtY.[E6].Value = rngRow.Cells(9).Value
        'Flight
        shtY.[K6].Value = rngRow.Cells(7).Value
         '차량
        shtY.[E7].Value = rngRow.Cells(2).Value
         '예약상품
        shtY.[E8].Value = rngRow.Cells(4).Value
          'Date
        shtY.[E9].Value = rngRow.Cells(1).Text & " " & rngRow.Cells(6).Text
          'Pax
        shtY.[E10].Value = rngRow.Cells(8).Value
         'Remark
        shtY.[E11].Value = rngRow.Cells(11).Value
        
        
        'save to pdf
        sFile = rngRow.Cells(2).Value & Replace(rngRow.Cells(1).Value, "-", "") & rngRow.Cells(9).Value
        shtY.ExportAsFixedFormat xlTypePDF, sFolder & "\" & sFile & ".pdf"
    
    Next
    
    shtY.Visible = xlSheetVeryHidden
    shtX.Activate
           
    Application.ScreenUpdating = True

End Sub
 
[불량 게시물 신고]  
참서리다음 YouTube 동영상에 자세히 설명되어 있습니다.
https://youtu.be/2tN_rOCNWBo
05-27 (07:03)
삭제 ■신고
        
  

작성일 : 2019-05-27(07:02)
최종수정일 : 2019-05-27(07:02)
 


 ◎ 관련글

  제 목   작성자   날짜
VBA고수님들 도와주세요 육씨럴놈뱅상 2019-05-26
[RE]VBA고수님들 도와주세요 참서리 2019-05-27