2017-02-07 1 views
0

Excel 스프레드 시트의 다른 탭에있는 차트에 데이터 포인트를 추가하려고합니다. 현재 차트 페이지를 열었을 때 추가되지만, 차트 페이지를 열 때 추가해야합니다 다른 탭에있다, 어떤 충고?다른 워크 시트의 차트에 데이터 포인트 추가

Sub Submit() 
    Dim Well_Outage As Long 
    Dim DP As Double 
    Dim i As Long 
    Dim j As Long 
    Dim myDocument As Worksheet 
    'Dim graph As Worksheet 

    Set myDocument = Worksheets(2) 
    Set graph = Worksheets 
    j = ActiveChart.SeriesCollection.Count 

    If myDocument.Cells(19, "I") = "" And myDocument.Cells(20, "I") = "" Then 
     MsgBox ("Enter Drilling and Production Lost Times") 
     Exit Sub 
    ElseIf myDocument.Cells(19, "I") = "" Then 
     MsgBox ("Enter Drilling Lost Times") 
     Exit Sub 
    ElseIf myDocument.Cells(20, "I") = "" Then 
     MsgBox ("Enter Production Lost Times") 
     Exit Sub 
    End If 

    i = 1 
    Well_Outage = myDocument.Cells(17, "L") 
    DP = (myDocument.Cells(19, "I")/myDocument.Cells(20, "I")) 
    DP = Round(DP, 1) 
    myDocument.Range("L6:L16").Value = "N" 
    myDocument.Range("I19:I20").Value = "" 

    Do While Not (myDocument.Cells(i, 1) = "") 
     i = i + 1 
    Loop 

    Do While Not (myDocument.Cells(i, 2) = "") 
     i = i + 1 
    Loop 

    myDocument.Cells(i, 1).Value = DP 
    myDocument.Cells(i, 2).Value = Well_Outage 

    ActiveChart.ChartArea.Select 
    ActiveChart.SeriesCollection.NewSeries 
    ActiveChart.FullSeriesCollection(j).XValues = (myDocument.Cells(i, 1)) 
    ActiveChart.FullSeriesCollection(j).values = (myDocument.Cells(i, 2)) 
    ActiveChart.ChartArea.Select 
    ActiveChart.FullSeriesCollection(j).Select 
    With Selection 
     .MarkerStyle = 8 
     .MarkerSize = 5 
    End With 
    Selection.MarkerStyle = -4168 
    Selection.MarkerSize = 6 
    Selection.MarkerSize = 7 
    Selection.MarkerSize = 8 
    Selection.MarkerSize = 9 
    Selection.MarkerSize = 10 
    With Selection.Format.line 
     .Visible = msoTrue 
     .weight = 2 
    End With 
    With Selection.Format.line 
     .Visible = msoTrue 
     .ForeColor.ObjectThemeColor = msoThemeColorText1 
     .ForeColor.TintAndShade = 0 
     .ForeColor.Brightness = 0 
     .Transparency = 0 
    End With 
    With Selection.Format.Fill 
     .Visible = msoTrue 
     .ForeColor.ObjectThemeColor = msoThemeColorText1 
     .ForeColor.TintAndShade = 0 
     .Transparency = 0 
     .Solid 
    End With 
    Selection.Format.Fill.Visible = msoFalse 
End Sub 

답변

0

당신은에 의해 사방 ActiveChart를 교체해야합니다 :

ThisWorkbook.Charts("yourChartName") 

또는 코드를 조금 단순화,

Dim ch as Chart 
Set ch = ThisWorkbook.Charts("yourChartName") 

그리고 사방 ch

에 의해 ActiveChart 대체이 내가 가지고있는 코드입니다
관련 문제