Option
Explicit
Sub
TestDiaErstellen()
Const
startm
As
Long
= 2
Const
endm
As
Long
= 10
Const
startf
As
Long
= 2
Const
endf
As
Long
= 10
Const
fPath
As
String
=
"C:\VBA\FrauDiagramm.xlsx"
Dim
chDiagramm
As
ChartObject
Dim
mPath
As
String
For
Each
chDiagramm
In
ActiveSheet.ChartObjects
chDiagramm.Delete
Next
chDiagramm
Set
chDiagramm = ActiveSheet.ChartObjects.Add(50, 100, 500, 350)
chDiagramm.Chart.ChartType = xlXYScatterLines
chDiagramm.Name =
"Einwohner"
With
chDiagramm.Chart.SeriesCollection.NewSeries
.XValues =
"=Tabelle1!A"
+
CStr
(startm) +
":A"
+
CStr
(endm)
.Values =
"=Tabelle1!B"
+
CStr
(startm) +
":B"
+
CStr
(endm)
.Name =
"Männer"
End
With
mPath = Mid(fPath, 1, InStrRev(fPath,
"\")) & "
[" & Mid(fPath, _
InStrRev(fPath,
"\") + 1, Len(fPath) - InStrRev(fPath, "
\"))
Debug.Print mPath
Workbooks.Open Replace(mPath,
"["
,
""
)
Workbooks(1).Activate
With
chDiagramm.Chart.SeriesCollection.NewSeries
.XValues =
"='["
+ Workbooks(2).Name +
"]Tabelle1'!A"
+
CStr
(startf) +
":A"
+
CStr
(endf)
.Values =
"='["
+ Workbooks(2).Name +
"]Tabelle1'!B"
+
CStr
(startf) +
":B"
+
CStr
(endf)
.Name =
"Frauen"
End
With
Workbooks(2).Close
False
End
Sub