Makrogenereret grafer i Excel
HejJeg har forsøgt mig med at lave et lagkagediagram udfra nogle givne værdier i et excel ark. For min egen nemheds skyld har jeg optaget makroen. Men det range, hvori værdierne findes er fast og det skal det ikke være, idet antallet kan variere. Den første værdi er altid i cellerne A6 og F6, men hvor mange rækker der er, kan variere. Kan jeg på nogle måder danne et automatisk range, efter antallet af rækker.
Jeg vedhæfter lige en kopi af makroen. Undskyld længden…….
Sub Graftotal()
Range("A6:a7,F6:F7").Select
Range("F6").Activate
Charts.Add
ActiveChart.ChartType = xl3DPie
ActiveChart.SetSourceData Source:=Sheets("sheet1").Range( _
"A6:A7,F6:F7"), PlotBy:=xlColumns
ActiveChart.SeriesCollection(1).Name = "=oversigt!R3C5"
ActiveChart.Location Where:=xlLocationAsObject, Name:="oversigt"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Oversigt"
End With
ActiveSheet.Shapes("Chart 1").IncrementLeft -181.5
ActiveSheet.Shapes("Chart 1").IncrementTop 47.25
ActiveSheet.Shapes("Chart 1").ScaleWidth 0.85, msoFalse, msoScaleFromTopLeft
ActiveSheet.Shapes("Chart 1").ScaleHeight 0.96, msoFalse, msoScaleFromTopLeft
With Selection.Border
.Weight = 2
.LineStyle = 0
End With
Selection.Interior.ColorIndex = xlNone
Sheets("sheet1").DrawingObjects("Chart 1").RoundedCorners = False
Sheets("sheet1").DrawingObjects("Chart 1").Shadow = False
Selection.AutoScaleFont = True
With Selection.Font
.Name = "arial"
.FontStyle = "Regular"
.Size = 8.5
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.Background = xlAutomatic
End With
ActiveChart.PlotArea.Select
With Selection.Border
.Weight = xlHairline
.LineStyle = xlNone
End With
With Selection.Interior
.ColorIndex = 16
.PatternColorIndex = 1
.Pattern = xlSolid
End With
ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).Points(2).Select
ActiveChart.SeriesCollection(1).Points(1).Select
With Selection.Border
.Weight = xlThin
.LineStyle = xlAutomatic
End With
With Selection.Interior
.ColorIndex = 7
.Pattern = xlSolid
End With
ActiveChart.SeriesCollection(1).Points(2).Select
With Selection.Border
.Weight = xlThin
.LineStyle = xlAutomatic
End With
With Selection.Interior
.ColorIndex = 44
.Pattern = xlSolid
End With
End Sub
