ActiveSheet.Shapes.AddChart2 다른 쉬트 데이터 참조하기

차트/그래프
작성자
꽃가마
작성일
2022-09-13 23:00
조회
1896
엑셀버전 : 엑셀2019

운영체제 : 윈도우10

질문 요약 : ActiveSheet.Shapes.AddChart2 다른 쉬트 데이터 참조하기를 했는데 ActiveSheet의 영역데이터도 자동으로 가져오지 않게 하는 법

아래는 차트를 그리는데 다른 쉬트의 분산된 자료를 배열로 받아와서 챠트의 데이터로 사용해서 그립니다

다 잘 되는데 항상 이상한 데이터가 더 그려지더군요

(첨부그림 오빠두엑셀 차트1)

이유를 찾다가 결국은 알았는데

ActiveSheet.Shapes.AddChart2

위의 명령어를 실행하면 아무것도 없이 기본적으로  ActiveSheet의 데이터를 가져오고, 그 다음에 지정한 데이터를 가져오니 이상한 라인이 첨부된 그래프가 되더군여

위의 명령어를 사용해서 다른 쉬트의 내용들을 참조하여 차트를 그릴 때

기본적으로 ActiveSheet의 데이터를 가져오지 않게 하려면

1) 어떻게 해야하나요?

2) 다른 명령어를 사용해야하나요?

 

참고: 밑에 있는 구문 짜느라고 엄청 구글링 했어요.

다른 쉬트의 데이터를 배열로 조합해 차트를 그리는 겁니다

비슷하긴 한데 완전하게 나온데가 없더군요

조금씩 안되요.

결국은 완성해서 잘 됩니다. 다른 분들도 사용하실 수 있어요. 공유합니다.

 

 

 

 

Sub 차트1()
'
' 매크로1 매크로
'
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.EnableEvents = False

Dim cht As ChartObject

Dim Arr As Variant
Dim Arr0 As Variant
Dim Arr1 As Variant
Dim Arr2 As Variant
Dim Arr3 As Variant
Dim Arr4 As Variant
Dim Arr5 As Variant
Dim Arr6 As Variant
Dim Arr7 As Variant
Dim Arr8 As Variant
Dim Arr9 As Variant
Dim Arr10(1, 111) As Variant
Dim Shp As Shape '각 도형을 넣을 변수

For Each Shp In ActiveSheet.Shapes '현재시트내 각 도형을 순환
If Shp.Type = msoChart Then '도형이 차트라면
Shp.Delete '도형을 삭제
End If
Next Shp

파일m = ThisWorkbook.Name
Set wm = Workbooks(파일m)
쉬트m = "전국흐름"
쉬트b = "매매지수"
쉬트c = "전세지수"
쉬트d = "매수매도"

끝행b = wm.Sheets(쉬트b).Cells(2, 2).End(xlDown).Row
끝행d = 끝행b

갈행 = ActiveCell.Row + 1
갈열 = ActiveCell.Column

'해당 지수열 찾기
For kk = 1 To 188
If Sheets(쉬트m).Cells(ActiveCell.Row, 4) = Sheets(쉬트b).Cells(1, kk) Then 지수열 = kk
Next

'매수매도 해당열
For kk = 1 To 73
If Sheets(쉬트m).Cells(ActiveCell.Row, 2) = Sheets(쉬트d).Cells(2, kk) Then 매수열 = kk
Next

'거래량열

'If MsgBox("끝행b=" & 끝행b & " 지수열=" & 지수열 & " 매수열=" & 매수열 & " Sheets(쉬트b).Cells(1, 지수열)=" & Sheets(쉬트b).Cells(1, 지수열), vbOKCancel) = vbCancel Then Exit Sub

'화면에 보이는 위치를 잡으면 좋겎는데
상단 = WorksheetFunction.Max(ActiveCell.Top - 높이, 350)
길이 = 750
높이 = 500
ActiveSheet.Shapes.AddChart2(227, xlLine, 150, 상단, 길이, 높이).Select

With ActiveChart

Arr0 = Range(wm.Sheets(쉬트b).Cells(4, 1), wm.Sheets(쉬트b).Cells(끝행b, 1))
Arr1 = Range(wm.Sheets(쉬트b).Cells(4, 지수열), wm.Sheets(쉬트b).Cells(끝행b, 지수열))
Arr2 = Range(wm.Sheets(쉬트c).Cells(4, 지수열), wm.Sheets(쉬트c).Cells(끝행b, 지수열))
Arr3 = Range(wm.Sheets(쉬트b).Cells(4, 지수열 + 376), wm.Sheets(쉬트b).Cells(끝행b, 지수열 + 376))
Arr4 = Range(wm.Sheets(쉬트c).Cells(4, 지수열 + 376), wm.Sheets(쉬트c).Cells(끝행b, 지수열 + 376))
Arr5 = Range(wm.Sheets(쉬트d).Cells(243 + 4, 매수열 + 2), wm.Sheets(쉬트d).Cells(243 + 끝행d, 매수열 + 2))
Arr6 = Range(wm.Sheets(쉬트d).Cells(243 + 4, 매수열 + 1), wm.Sheets(쉬트d).Cells(243 + 끝행d, 매수열 + 1))
Arr7 = Range(wm.Sheets(쉬트b).Cells(4, 지수열 + 188), wm.Sheets(쉬트b).Cells(끝행b, 지수열 + 188))
Arr8 = Range(wm.Sheets(쉬트c).Cells(4, 지수열 + 188), wm.Sheets(쉬트c).Cells(끝행b, 지수열 + 188))

'.SetSourceData Source:=Range("$bd$210:$bi$932")
.FullSeriesCollection(1).XValues = Arr0

'.SeriesCollection.NewSeries
.FullSeriesCollection(1).Values = Arr1
.FullSeriesCollection(1).ChartType = xlLine
.FullSeriesCollection(1).AxisGroup = 1
'.SeriesCollection.NewSeries
.FullSeriesCollection(2).Values = Arr2
.FullSeriesCollection(2).ChartType = xlLine
.FullSeriesCollection(2).AxisGroup = 1
'.SeriesCollection.NewSeries
.FullSeriesCollection(3).Values = Arr3
.FullSeriesCollection(3).ChartType = xlLine
.FullSeriesCollection(3).AxisGroup = 1
'.SeriesCollection.NewSeries
.FullSeriesCollection(4).Values = Arr4
.FullSeriesCollection(4).ChartType = xlLine
.FullSeriesCollection(4).AxisGroup = 1

'.SeriesCollection.NewSeries
.FullSeriesCollection(5).Values = Arr5
.FullSeriesCollection(5).ChartType = xlLine
.FullSeriesCollection(5).AxisGroup = 1
'.SeriesCollection.NewSeries
.FullSeriesCollection(6).Values = Arr6
.FullSeriesCollection(6).ChartType = xlLine
.FullSeriesCollection(6).AxisGroup = 1
'.SeriesCollection.NewSeries
.FullSeriesCollection(7).Values = Arr7
.FullSeriesCollection(7).ChartType = xlColumnClustered
.FullSeriesCollection(7).AxisGroup = 2
'.SeriesCollection.NewSeries
.FullSeriesCollection(8).Values = Arr8
.FullSeriesCollection(8).ChartType = xlLine
.FullSeriesCollection(8).AxisGroup = 2

.HasTitle = True
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlSecondary).HasTitle = True

.ChartTitle.Caption = Sheets(쉬트m).Cells(ActiveCell.Row, 3)
.Axes(xlValue, xlPrimary).AxisTitle.Text = "지수 2년누적매매.전세 매수우위.매수 매매.전세 "
.Axes(xlValue, xlSecondary).AxisTitle.Text = "매매.전세 증감율"
.Axes(xlCategory, xlPrimary).AxisTitle.Text = "년월"
'.Axes(XValues, xlPrimary).AxisTitle.Text = "년월"

.Axes(xlValue, xlPrimary).MinimumScale = -20
.Axes(xlValue, xlPrimary).MaximumScale = 180
'.Axes(xlCategory, xlPrimary).MajorUnit = 4
.Axes(xlValue, xlPrimary).MajorUnit = 10
.Axes(xlValue, xlSecondary).MinimumScale = -4
.Axes(xlValue, xlSecondary).MaximumScale = 1

.HasLegend = True
.Legend.Position = xlLegendPositionBottom
.SeriesCollection(1).Name = "매매지수"
.SeriesCollection(2).Name = "전세지수"
.SeriesCollection(3).Name = "매매2년누적"
.SeriesCollection(4).Name = "전세2년누적"
.SeriesCollection(5).Name = "매수우위"
.SeriesCollection(6).Name = "매수"
.SeriesCollection(7).Name = "매매증감"
.SeriesCollection(8).Name = "전세증감"

'RGB 표 https://www.rapidtables.org/ko/web/color/RGB_Color.html
.SeriesCollection(1).Format.Line.Visible = msoFalse
.SeriesCollection(1).Format.Line.Visible = msoTrue
.SeriesCollection(1).Format.Line.ForeColor.RGB = RGB(0, 0, 255)
'.SeriesCollection(1).Format.Line.DashStyle = msoLineSysDot 'msoLineSysDot msoLineSysDash
.SeriesCollection(1).Format.Line.Weight = 2

.SeriesCollection(2).Format.Line.Visible = msoTrue
.SeriesCollection(2).Format.Line.ForeColor.RGB = RGB(255, 0, 0)
'.SeriesCollection(2).Format.Line.DashStyle = msoLineSysDot 'msoLineSysDot msoLineSysDash
.SeriesCollection(2).Format.Line.Weight = 2

.SeriesCollection(3).Format.Line.Visible = msoTrue
.SeriesCollection(3).Format.Line.ForeColor.RGB = RGB(0, 102, 0)
'.SeriesCollection(3).Format.Line.DashStyle = msoLineSysDot 'msoLineSysDot msoLineSysDash
.SeriesCollection(3).Format.Line.Weight = 2

.SeriesCollection(4).Format.Line.Visible = msoTrue
.SeriesCollection(4).Format.Line.ForeColor.RGB = RGB(153, 0, 0)
'.SeriesCollection(4).Format.Line.DashStyle = msoLineSysDot 'msoLineSysDot msoLineSysDash
.SeriesCollection(4).Format.Line.Weight = 2

.SeriesCollection(5).Format.Line.Visible = msoTrue
.SeriesCollection(5).Format.Line.ForeColor.RGB = RGB(102, 204, 0)
.SeriesCollection(5).Format.Line.DashStyle = msoLineSysDot 'msoLineSysDot msoLineSysDash
.SeriesCollection(5).Format.Line.Weight = 2

.SeriesCollection(6).Format.Line.Visible = msoTrue
.SeriesCollection(6).Format.Line.ForeColor.RGB = RGB(255, 0, 255)
.SeriesCollection(6).Format.Line.DashStyle = msoLineSysDot 'msoLineSysDot msoLineSysDash
.SeriesCollection(6).Format.Line.Weight = 2

.SeriesCollection(7).Format.Line.Visible = msoTrue
.SeriesCollection(7).Format.Line.ForeColor.RGB = RGB(0, 0, 255)
'.SeriesCollection(7).Format.Line.DashStyle = msoLineSysDot 'msoLineSysDot msoLineSysDash
.SeriesCollection(7).Format.Line.Weight = 0.1

.SeriesCollection(8).Format.Line.Visible = msoTrue
.SeriesCollection(8).Format.Line.ForeColor.RGB = RGB(255, 0, 0)
'.SeriesCollection(8).Format.Line.DashStyle = msoLineSysDot 'msoLineSysDot msoLineSysDash
.SeriesCollection(8).Format.Line.Weight = 0.1

'.FullSeriesCollection(1).MarkerSize = 10
'.SeriesCollection(1).Interior.Color = "yellow"

End With

Sheets(쉬트m).Cells(갈행, 갈열).Select

'ActiveWindow.ScrollRow = 1
'SendKeys ("{down}")

Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.EnableEvents = False

End Sub

오빠두엑셀-차트1.png

신고
스크랩
공유
회원등급 : 4레벨
포인트 : 238 EP
총질문 : 7 개 (마감율 : 29%)
채택답변 : 0 개
전체 1

  • 2022-10-01 17:49

    아, 근 1달만에 해결했어요

    이유는 모르겠지만, 앞의 차트를 다 지우고 했어요

    요 코드중 아래 모두 지우기를 넣었어요.

     


전체 18,457
번호 카테고리 제목 작성자 작성일 추천 조회
알림
[📚진짜쓰는 실무엑셀] IT/오피스 '1위' 베스트셀러! 엑셀 공부, 이 교재로 마스터하세요! (313)
오빠두엑셀 | 2022.02.03 | 추천 572 | 조회 598945
오빠두엑셀 2022.02.03 572 598945
공지사항 문서서식
⭐ [더 나은 커뮤니티 문화를 위한 Q&A 글 작성 규칙] ⭐ (197)
오빠두엑셀 | 2021.10.28 | 추천 310 | 조회 34863
오빠두엑셀 2021.10.28 310 34863
78396 함수/공식
New 직원별로 근태 합계를 확인하고 싶어요 엑셀파일
배진희 | 13:50 | 추천 0 | 조회 4
배진희 13:50 - 4
78395 함수/공식
New 특정 단어를 포함한 행 골라내는 방법에 대해 문의드립니다.
mmm1010 | 13:36 | 추천 0 | 조회 8
mmm1010 13:36 - 8
78389 기능/도구
New 오빠두LIVE 196회 - 엑셀 프로젝트 관리 _ 일,주 바꾸는법 엑셀파일
일류 | 09:21 | 추천 0 | 조회 30
일류 09:21 - 30
78387 함수/공식
New 엑셀 관련 질문입니다. SUM과 IFERROR 입니다 ㅠ (5)
| 2025.04.27 | 추천 0 | 조회 78
2025.04.27 - 78
78382
New Excel 추세선 이상 엑셀파일 (1)
eagle | 2025.04.27 | 추천 0 | 조회 58
eagle 2025.04.27 - 58
78381 함수/공식
New 같은 이름 N 번째 데이터 엑셀파일첨부파일 (14)
박정호 | 2025.04.27 | 추천 1 | 조회 95
박정호 2025.04.27 1 95
78380 함수/공식
New On Error Resume Next 문구를 삽입하는 위치는? (2)
GEEM | 2025.04.27 | 추천 0 | 조회 65
GEEM 2025.04.27 - 65
78376 함수/공식
New 지역별 증감금액 확인 엑셀파일 (3) 답변완료
충무공 | 2025.04.26 | 추천 0 | 조회 65
충무공 2025.04.26 - 65
78374 함수/공식
New index를 활용한 조건에 맞는 금액을 찾는 방법 엑셀파일첨부파일 (4)
뚜둥뚜둥 | 2025.04.26 | 추천 0 | 조회 75
뚜둥뚜둥 2025.04.26 - 75
78372 기능/도구
New 표서식 차이 문의 첨부파일 (2) 답변완료
hossang**** | 2025.04.25 | 추천 0 | 조회 53
hossang**** 2025.04.25 - 53
78370 피벗테이블
New (피벗테이블) 2024년 2025년 판매 TOP10 비교데이터 첨부파일 (13)
패션피플 | 2025.04.25 | 추천 0 | 조회 74
패션피플 2025.04.25 - 74
78369 구글시트
New 엑셀을 구글 시트와 연동하는 법 (1)
물만둡 | 2025.04.25 | 추천 0 | 조회 58
물만둡 2025.04.25 - 58
78368 함수/공식
New 곱하기 계산시 0일때도 계산하고 싶습니다 엑셀파일 (2)
또야 | 2025.04.25 | 추천 0 | 조회 71
또야 2025.04.25 - 71
78366
New 엑셀 일정 범위 내 최대값 가져오기 함수식 문의 (조건 있음) 엑셀파일 (3)
peac**** | 2025.04.25 | 추천 0 | 조회 53
peac**** 2025.04.25 - 53
78358
New 파워포인트 글씨 굵게 (1)
쫄면김밥 | 2025.04.24 | 추천 0 | 조회 31
쫄면김밥 2025.04.24 - 31
78354 문서서식
New 구글스프레드시트 숨기기 질문이에요! 첨부파일 (1)
Aberdeen | 2025.04.24 | 추천 0 | 조회 54
Aberdeen 2025.04.24 - 54
78352 피벗테이블
New 여러 피벗테이블 하나의 슬라이서로 동작과 테이블간 관계 만들기 문의 엑셀파일첨부파일 (3) 답변완료
이미자 | 2025.04.24 | 추천 0 | 조회 73
이미자 2025.04.24 - 73
78347 대시보드
New 대시보드 결과 값끼리 열 비교하기 (4)
아네모네 | 2025.04.24 | 추천 0 | 조회 69
아네모네 2025.04.24 - 69
78346 함수/공식
New 요일별 색상 구분 엑셀파일 (4)
슈토파이터 | 2025.04.24 | 추천 0 | 조회 78
슈토파이터 2025.04.24 - 78
78344 VBA
New 첫 셀에만 수식입력하면 열 전체가 자동으로 수식 적용되는 기능 푸는방법 문의 첨부파일 (6) 답변완료
나라달 | 2025.04.24 | 추천 0 | 조회 101
나라달 2025.04.24 - 101
78342
New 만년 달력 관련 도와주세요.ㅠㅠ
주식회사 티에프티 | 2025.04.24 | 추천 0 | 조회 50
주식회사 티에프티 2025.04.24 - 50
78341 함수/공식
New sumproduct 조건에 관해서 (1)
쪼쪼 | 2025.04.24 | 추천 0 | 조회 77
쪼쪼 2025.04.24 - 77
78340 피벗테이블
New 다중영역 피벗테이블에서 영역을 표만들기로 적용하는 경우 오류발생, 원인을 모르겠습니다 엑셀파일첨부파일 (2)
S지니 | 2025.04.24 | 추천 0 | 조회 47
S지니 2025.04.24 - 47
78339 함수/공식
New 엑셀이느려집니다 ㅠ 자동견적서만드는데 VLOOKUP을 너무많이써서그런가 원인좀 봐주세요 (2)
리더실드 | 2025.04.24 | 추천 0 | 조회 85
리더실드 2025.04.24 - 85
78335
New 인쇄시 양식을 배경으로 깔 수 있을까요? (1)
emma6094 | 2025.04.24 | 추천 0 | 조회 34
emma6094 2025.04.24 - 34
78332 기능/도구
New 고수님들 질문들립니다. GPT 엑셀 연동 으로 데이터수집 관련 (2)
왕뚜껑 | 2025.04.23 | 추천 0 | 조회 79
왕뚜껑 2025.04.23 - 79
78330 함수/공식
New 15분마다 쌓이는 데이터를 1시간 단위로 합산해서 정리하고싶어요.. 엑셀파일 (3)
sj | 2025.04.23 | 추천 0 | 조회 112
sj 2025.04.23 - 112
78327 VBA
New 엑셀 VBA 챌린지 2일차, 값바꾸기 버튼 클릭해도 안 바뀌는 이유 첨부파일 (8)
Babelfish | 2025.04.23 | 추천 0 | 조회 65
Babelfish 2025.04.23 - 65
78326 함수/공식
New 여러 열의 데이터가 중복될때 표시되는 조건부서식을 할때요 엑셀파일 (2) 답변완료
윷즈 | 2025.04.23 | 추천 0 | 조회 75
윷즈 2025.04.23 - 75
78324 함수/공식
New CVS 파일의 특정 셀만 추출하고 싶습니다. 첨부파일 (11) 답변완료
기니피그93 | 2025.04.23 | 추천 0 | 조회 79
기니피그93 2025.04.23 - 79