AW: du hast es nicht verstanden
07.05.2015 17:12:13
Klaus
Hallo Nils,
ich ignoriere mal deine Art. Kann mir schon vorstellen, dass du händeringend um Hilfe suchst und etwas Ironie bei dir nicht ankommt.
Man muss sich schon mal eine Stunde Zeit nehmen, eine ordentliche Mustertabelle zu erstellen. Meistens reicht es schon, das Firmenlogo zu löschen, ein paar Zahlen durch Zufallszahlen zu ersetzen und statt Namen immer "Max Mustermann"-Varianten zu nutzen. Aber in der heutigen Zeit von Datenkraken, Facebook und Spam-Robotern ist es sehr begrüßenswert wenn jemand auf seine Datenautonomität achtet - das meine ich völlig ironiefrei.
Problem: Du schreibst selbst, dein Problem ist sehr komplex. Wie soll sich ein Helfer eine komplexe Lösung ohne jede Vorlage aus dem Ärmel schütteln?
Wenn ich variable Diagramme brauche, erstelle ich sie meistens ad Hoc. Dazu habe ich mir mal mit Hilfe des Forums, wenn ich mich Recht erinnere mit großer Hilfe von Rudi, ein Standard-Makro gebaut und gespeichert. Vielleicht schaffst du es ja darauf aufbauend, eine Lösung für dein Problem zu entwickeln! Ansatz: Statt ein vorhandenes Diagramm zu verbiegen, lieber ein neues und richtiges Diagramm erstellen.
Option Explicit
'* Module for quick creation of charts in the active worksheet
'* created: June 2013 by Klaus MvdT
'* every feature after data-Range is optional!
Sub test()
Call MakeSingleChart(Range("B4:C12"), 1, Range("A1"), 300, 200, 10, 90, True)
Call MakeSingleChart(Range("B4:C12"), , , , , , , False)
Call MakeSingleChart(Range("B4:C12"))
End Sub
Sub MakeSingleChart( _
rngData As Range, _
Optional TypeChart As Integer, _
Optional rngTopLeftCell As Variant, _
Optional iHeight As Variant, _
Optional iWidth As Variant, _
Optional iScaleMin As Variant, _
Optional iScaleMax As Variant, _
Optional bNoLegend As Boolean)
'rngData = Range of Data
'TypeChart 1=Line, 2=Pie, 3=Column, 4=ColumnStacked, 5=ColumStacked100, none=Line
'rngTopLeftCell = Move Chart's top left corner to THIS cell, places in mid-screen if not _
choosen
'iHeight and iWidth = Height/Width in Pixels, uses standard if not choosen
'iScaleMin and iScaleMax = FIX X-Axis to this value. If not choosen, chart will autoscale
'bNoLegend = if TRUE, Legend is removed. If FALSE or not choosen, Legend stays in the chart
On Error GoTo hell
'rngTopLeftCell hast to be a valid RANGE, iHeight a valid INTEGER and so on
' Declaration has to be VARIANT to enable the ISMISSING feature. In case of wrong usage
' (example: set height to "hello world") it will end with ONERROR
Dim myCht As Object
Set myCht = ActiveSheet.Shapes.AddChart 'create new Chart
With myCht
With .Chart
'Chart definitions ************************************
.ChartType = xlLine 'set Line as standard
Select Case TypeChart
Case 1
Case 2
.ChartType = xlPie
Case 3
.ChartType = xlColumnClustered
Case 4
.ChartType = xlColumnStacked
Case 5
.ChartType = xlColumnStacked100
Case Else
End Select
.SetSourceData Source:=rngData
' ************************************ Chart Definitions
If bNoLegend Then .Legend.Delete 'Legend or not?
End With
'move and scale ************************************
If Not IsMissing(iScaleMax) Then .Chart.Axes(xlValue).MaximumScale = iScaleMax
If Not IsMissing(iScaleMin) Then .Chart.Axes(xlValue).MinimumScale = iScaleMin
If Not IsMissing(rngTopLeftCell) Then
.Top = rngTopLeftCell.Top
.Left = rngTopLeftCell.Left
End If
If Not IsMissing(iHeight) Then .Height = iHeight
If Not IsMissing(iWidth) Then .Width = iWidth
'************************************ move and scale
End With
GoTo heaven:
hell:
'get rid of wrong chart
myCht.Delete
'display error messge
MsgBox "could not create chart!" & vbCrLf _
& "Error Number: " & Err.Number & _
vbCrLf & "Error: " & Err.Description
heaven:
End Sub
Über eine Rückmeldung, ob du damit zumindest etwas weiter kommst, würd ich mich sehr freuen.
Grüße,
Klaus M.vdT.