책 내용 질문하기
매크로에서 단추1이 자꾸 생깁니다
도서
2019 시나공 컴퓨터활용능력 1급 실기
페이지
337
조회수
264
작성일
2020-02-14
작성자
탈퇴*원
첨부파일

문제3 2 분석작업-2에

 

매크로를 완성하면 자꾸 단추1이 생기네요...

 

원인이 뭔가요 ㅠ

 

첨부파일 넣었습니다.

답변
2020-02-16 20:55:20

정확하게 왜 그런 결과가 나왔는지는 모르겠지만

 

매크로 내용에 문제에 필요하지 않은 내용이 기록된 것 같네요.

 

Sub 부분합()
'
' 부분합 매크로
'

'
    Range("A3:I12").Select
    ActiveWorkbook.Worksheets("분석작업-2").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("분석작업-2").Sort.SortFields.Add Key:=Range("D4:D12") _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("분석작업-2").Sort
        .SetRange Range("A3:I12")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Range("A3:I12").Select
    Selection.Subtotal GroupBy:=4, Function:=xlAverage, TotalList:=Array(6), _
        Replace:=True, PageBreaks:=False, SummaryBelowData:=True
    Range("A3:I16").Select
    Selection.Subtotal GroupBy:=4, Function:=xlSum, TotalList:=Array(6), _
        Replace:=False, PageBreaks:=False, SummaryBelowData:=True
    Range("K13").Select
    ActiveWindow.SmallScroll Down:=-3
    Range("A1:I20").Select
    Selection.Copy
    Application.CutCopyMode = False
    Range("A9").Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .Color = -16776961
        .TintAndShade = 0
        .Weight = xlThick
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .Color = -16776961
        .TintAndShade = 0
        .Weight = xlThick
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Color = -16776961
        .TintAndShade = 0
        .Weight = xlThick
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .Color = -16776961
        .TintAndShade = 0
        .Weight = xlThick
    End With

End Sub 

 

단추1로 표시된 부분은 삭제하셨다가 삽입 하셔서 원본 데이터값을 넣은 후

 

빨간색으로 표시된 부분을 제거 하면 정상 실행이 가능 합니다.

 

매크로 실행전에 부분합 제거를 한 후 실행 하셔야 합니다.

 

매크로 편집을 실행하시면 프로시저가 나타나는데 프로시저를 수정 하시면 되구요.

 

수정이 힘드시다면 매크로를 삭제 하신 후 다시 설정 해 보시기 바랍니다.

 

좋은 하루 되세요.  

  • 관리자
    2020-02-16 20:55:20

    정확하게 왜 그런 결과가 나왔는지는 모르겠지만

     

    매크로 내용에 문제에 필요하지 않은 내용이 기록된 것 같네요.

     

    Sub 부분합()
    '
    ' 부분합 매크로
    '

    '
        Range("A3:I12").Select
        ActiveWorkbook.Worksheets("분석작업-2").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("분석작업-2").Sort.SortFields.Add Key:=Range("D4:D12") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("분석작업-2").Sort
            .SetRange Range("A3:I12")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        Range("A3:I12").Select
        Selection.Subtotal GroupBy:=4, Function:=xlAverage, TotalList:=Array(6), _
            Replace:=True, PageBreaks:=False, SummaryBelowData:=True
        Range("A3:I16").Select
        Selection.Subtotal GroupBy:=4, Function:=xlSum, TotalList:=Array(6), _
            Replace:=False, PageBreaks:=False, SummaryBelowData:=True
        Range("K13").Select
        ActiveWindow.SmallScroll Down:=-3
        Range("A1:I20").Select
        Selection.Copy
        Application.CutCopyMode = False
        Range("A9").Select
        Selection.Borders(xlDiagonalDown).LineStyle = xlNone
        Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With Selection.Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .Color = -16776961
            .TintAndShade = 0
            .Weight = xlThick
        End With
        With Selection.Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .Color = -16776961
            .TintAndShade = 0
            .Weight = xlThick
        End With
        With Selection.Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .Color = -16776961
            .TintAndShade = 0
            .Weight = xlThick
        End With
        With Selection.Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .Color = -16776961
            .TintAndShade = 0
            .Weight = xlThick
        End With

    End Sub 

     

    단추1로 표시된 부분은 삭제하셨다가 삽입 하셔서 원본 데이터값을 넣은 후

     

    빨간색으로 표시된 부분을 제거 하면 정상 실행이 가능 합니다.

     

    매크로 실행전에 부분합 제거를 한 후 실행 하셔야 합니다.

     

    매크로 편집을 실행하시면 프로시저가 나타나는데 프로시저를 수정 하시면 되구요.

     

    수정이 힘드시다면 매크로를 삭제 하신 후 다시 설정 해 보시기 바랍니다.

     

    좋은 하루 되세요.  

· 5MB 이하의 zip, 문서, 이미지 파일만 가능합니다.
· 폭언, 욕설, 비방 등은 관리자에 의해 경고없이 삭제됩니다.