저는 vba를 처음 사용하며 Excel 페이지에서 vba 차트를 배치하려고합니다. 아래는 코드입니다. 내가 교체하는 경우 :vba 차트 위치를 정의합니다.
Set c = c.Location(Where:=xlLocationAsObject, Name:=chLoc.Parent.Name)
Set c = c.Location(Where:=xlLocationAsObject, Name:="Sheet1")
으로 다음 코드는 작동합니다. 그렇지 않으면 내가 '객체의' '오류 1004 방법'범위를 얻을 수 _Worksheet은 '실패와 오류가 줄에 발생합니다 여기
Set chLoc = sh2.Range(sh2.[a1:g10])
코드입니다 - 감사 및 VBA 차트에 대한 좋은 자료가 있다면 나는 감사하겠습니다 어떤 방향 :
Sub Chart()
Dim sh1 As Worksheet
Dim sh2 As Worksheet
Dim xaxis As Range
Dim yaxis As Range
Set sh1 = ActiveWorkbook.Sheets("Spon Email Performance Graph")
Set sh2 = ActiveWorkbook.Sheets("Graphs")
Set xaxis = sh1.Range(sh1.[b15], sh1.[b15].End(xlDown))
Set yaxis = sh1.Range(sh1.[g15], sh1.[g15].End(xlDown))
Dim chLoc As Range
Set chLoc = sh2.Range(sh2.[a1:g10])
' Worksheets("Graphs").ChartObjects.Delete
Dim c As Chart
Set c = Charts.Add
Set c = c.Location(Where:=xlLocationAsObject, Name:=chLoc.Parent.Name)
With c
.ChartType = xlColumnClustered
' set other chart properties
End With
Dim s As Series
Set s = c.SeriesCollection.NewSeries
With s
.Values = yaxis
.XValues = xaxis
' set other series properties
End With
End Sub
당신은 코드 대신 sh2.Range의, 더 신뢰할 수 원하는 IIF : (sh2.Range를 사용 (SH2 [A1 G10가].) "A1 : G10"). –