seraslibre
New Member
- Joined
- Sep 1, 2009
- Messages
- 9
I have created a function to generate an x-y chart that I call on to generate about 40 charts (hence the number of inputs to the function). However, every time I open excel to run the macro, the field sizes are different, and rarely correspond to what I have set in the macro. i.e. The chart title field is set to 14pt size, but that is rarely the case in the end product. All the other fields, including axis name size, scale text size, and legend size, are all strange sizes. I would say 50% of the time the fiels are the correct size, with the exception of the title field which is usually larger 80% of the time.
Any ideas?
Any ideas?
Code:
Function PlotRamps(Worksheet As String, firstcol As Integer, StartRow As Integer, chartheight As Single, nextcharth As Single, chartwidth As Single, nextchartw As Single)
Dim dataLength As Integer
dataLength = Range("A11", Range("A11").End(xlDown)).Rows.Count + 100
Dim Datasets As Integer
Datasets = Range("A11", Range("A11").End(xlToRight)).Cells.Count
Dim myChtObj As ChartObject
Dim rngChtYval As Range
Dim rngChtXval As Range
Dim Title As String
Dim RampType As String
Dim startcol As Integer
startcol = firstcol
If StartRow = 11 Then
RampType = "Engagement"
Else
RampType = "Disengagement"
End If
Title = RampType & " Ramp p=" & Cells(5, startcol) & "; T=" & Cells(6, startcol) & "; n= 0-300-0 rpm"
With Sheets(Worksheet)
Set myChtObj = Sheets(Worksheet).ChartObjects.Add(Left:=nextchartw, Width:=chartwidth, Top:=nextcharth, Height:=chartheight)
With myChtObj.Chart
.ChartType = xlXYScatterLinesNoMarkers
Do Until .SeriesCollection.Count = 0
.SeriesCollection(1).delete
Loop
Do While startcol <= Datasets
Set rngChtXval = Range(Cells(StartRow, startcol), Cells(StartRow + dataLength, startcol))
Set rngChtYval = Range(Cells(StartRow, startcol + 1), Cells(StartRow + dataLength, startcol + 1))
With .SeriesCollection.NewSeries
.Values = rngChtYval
.XValues = rngChtXval
.Name = Cells(7, startcol)
End With
startcol = startcol + 18
Loop
.HasTitle = True
.ChartTitle.text = Title
.ChartTitle.Font.Size = 14
.Legend.Font.Size = 10
.Legend.Height = 200
With .Axes(xlCategory, xlPrimary)
.HasTitle = True
.AxisTitle.Characters.text = "Sliding Speed in rpm"
.AxisTitle.Font.Size = 12
End With
With .Axes(xlValue, xlPrimary)
.HasTitle = True
.AxisTitle.Characters.text = "Mu"
.AxisTitle.Font.Size = 12
End With
With .Axes(xlCategory)
.MaximumScale = 300
.MinimumScale = 0
.MajorUnit = 60
.AxisTitle.Font.Size = 10
.AxisTitle.Font.Bold = False
.TickLabels.Font.Size = 10
If StartRow <> 11 Then
.ReversePlotOrder = True
End If
End With
With .Axes(xlValue)
.MaximumScale = 0.2
.MinimumScale = 0
.MajorUnit = 0.02
.AxisTitle.Font.Size = 10
.AxisTitle.Font.Bold = False
.TickLabels.Font.Size = 10
End With
End With
End With
End Function