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

 참서리 (k5953)

추천:  2
파일:     차트 Y축 자동 변경-1.xls (54KB) 조회:  2101
제목:   [RE]차트 Y축 자동 변경 VBA 문의
     
  '-------------------------------------
Sub chart_change()
'-------------------------------------



    Dim ochart As Excel.Chart
    
    Set ochart = Sheet1.ChartObjects(1).Chart
    
    Dim data As Variant
     
      
    data = get_data
        
    Dim oseries As Excel.Series
    
    Set oseries = ochart.SeriesCollection(1)
    oseries.Name = "Sales"
    oseries.xvalues = data(0)
    oseries.Values = data(1)
    
    Set oseries = ochart.SeriesCollection(2)
    oseries.Name = "Value"
    oseries.xvalues = data(0)
    oseries.Values = data(2)
     
        
        
        
    
End Sub




' 숨김 데이타를 제외한 데이타 가져오기

'-------------------------------------
Function get_data() As Variant
'-------------------------------------


    Dim rngx As Range
    Set rngx = Sheet2.Range("B2").CurrentRegion
    Dim row As Range
    
    Dim xvalues As Variant, y1values As Variant, y2values As Variant
    
    xvalues = Array()
    y1values = Array()
    y2values = Array()
    
    
    
    For r = 2 To rngx.Rows.Count
    
       If Not (rngx.Rows.Item(r).Hidden) Then
       
            With rngx.Rows.Item(r)
                 xvalues = push(xvalues, .Cells(1).Value)
                 y1values = push(y1values, .Cells(2).Value)
                 y2values = push(y2values, .Cells(3).Value)
             End With
        
       End If
        
    Next
    

' 최소값, 최대값 환산

imax = WorksheetFunction.Max(y1values)
Index = WorksheetFunction.Match(imax, y1values, 0)
imax = imax * 1.1
y1values(Index - 1) = imax

imin = WorksheetFunction.Min(y1values)
Index = WorksheetFunction.Match(imin, y1values, 0)
imin = imin * 0.9
y1values(Index - 1) = imin

imax = WorksheetFunction.Max(y2values)
Index = WorksheetFunction.Match(imax, y2values, 0)
imax = imax * 1.1
y2values(Index - 1) = imax

imin = WorksheetFunction.Min(y2values)
Index = WorksheetFunction.Match(imin, y2values, 0)
imin = imin * 0.9
y2values(Index - 1) = imin

get_data = Array(xvalues, y1values, y2values)


End Function


' 배열 요소 추가
'-------------------------------------------------------
Function push(col As Variant, ele As Variant) As Variant
'-------------------------------------------------------

    Dim i As Long: i = UBound(col, 1) + 1
    ReDim Preserve col(i)
    
    col(i) = ele
    
    push = col


End Function

 
[불량 게시물 신고]  
신주안녕하세요, 먼저 깊은 수고와 도움에 감사 드립니다! 제가 잘 다운받아서 매크로를 실행시켰음에도 불구하고,, Y축 값이 변하지 않네요.. 잘 모르는 수식을 찬찬히 살펴봐도 문제는 없어 보이는데 확인 부탁 드려도 될까요 ㅠ11-26 (09:23)
삭제 ■신고
        
  

작성일 : 2018-11-24(23:55)
최종수정일 : 2018-11-24(23:55)
 


 ◎ 관련글

  제 목   작성자   날짜
차트 Y축 자동 변경 VBA 문의 신주현 2018-11-23
[RE]차트 Y축 자동 변경 VBA 문의 dew 2018-11-26
[RE]차트 Y축 자동 변경 VBA 문의 참서리 2018-11-24
[RE]차트 Y축 자동 변경 VBA 문의 참서리 2018-11-26