Hi all,
I'm a beginner on VBA, and sorry if my code is not clean. i'm trying to create a Pareto chart on the same worksheet where i already have another column chart. I used the Macro recorder to get the code.
The First Chart is working fine. When i try to add the second chart ( Pareto ), i'm getting a error message: Run Time error ' -21470224809(80070057) The specified value is out of range."
I have added this to the code ( ActiveSheet.Shapes.AddChart2(5, xlPareto).Select ), because when i execute the macro recorder this not appear on the code generate by the process, and when i try to proceed the Chart was reffering to the first chart ( Column Chart ) and not to the new one that i'm trying to create. I don't know why. Maybe this can be related to this error somehow.
This is the Function below :
Sub ParetoGraph(xPin, xPfi, xcL2, xcL1, xL2, xL1)
Range(xPin & ":" & xPfi).Select
ActiveSheet.Shapes.AddChart2(5, xlPareto).Select
ActiveChart.Parent.Name = "4Q Pareto"
ActiveSheet.ChartObjects("4Q Pareto").Activate
ActiveWindow.SmallScroll Down:=-9
ActiveSheet.Shapes("4Q Pareto").IncrementLeft 168
ActiveSheet.Shapes("4Q Pareto").IncrementTop -134.25
ActiveWindow.SmallScroll Down:=-6
ActiveSheet.Shapes("4Q Pareto").IncrementLeft -12.75
ActiveSheet.Shapes("4Q Pareto").IncrementTop -122.25
ActiveSheet.Shapes("4Q Pareto").Chart.HasTitle = True
ActiveSheet.Shapes("4Q Pareto").TextFrame2.TextRange.Characters.Text = "LATE - Root Cause"
ActiveSheet.Shapes("4Q Pareto").TextFrame2.TextRange.Characters(1, 17).ParagraphFormat.Alignment = msoAlignCenter
With ActiveSheet.Shapes("4Q Pareto").TextFrame2.TextRange.Characters(1, 17).Font
.BaselineOffset = 0
.Bold = msoFalse
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(89, 89, 89)
.Fill.Transparency = 0
.Fill.Solid
.Size = 14
.Italic = msoFalse
.Kerning = 12
.Name = "Calibri"
.UnderlineStyle = msoNoUnderline
.Spacing = 0
.Strike = msoNoStrike
End With
Range("N21").Select
ActiveWindow.SmallScroll Down:=15
Range("C25").Select
ActiveWindow.SmallScroll Down:=-12
ActiveSheet.Shapes.Range(Array("4Q Pareto")).Select
ActiveWindow.SmallScroll Down:=6
ActiveChart.SetSourceData Source:=Range("'4Q Report'!$C$26:$G$&xcL2")
Range("N21").Select
ActiveWindow.SmallScroll Down:=-12
End Sub
Thanks in advanced...
Tadeu
I'm a beginner on VBA, and sorry if my code is not clean. i'm trying to create a Pareto chart on the same worksheet where i already have another column chart. I used the Macro recorder to get the code.
The First Chart is working fine. When i try to add the second chart ( Pareto ), i'm getting a error message: Run Time error ' -21470224809(80070057) The specified value is out of range."
I have added this to the code ( ActiveSheet.Shapes.AddChart2(5, xlPareto).Select ), because when i execute the macro recorder this not appear on the code generate by the process, and when i try to proceed the Chart was reffering to the first chart ( Column Chart ) and not to the new one that i'm trying to create. I don't know why. Maybe this can be related to this error somehow.
This is the Function below :
Sub ParetoGraph(xPin, xPfi, xcL2, xcL1, xL2, xL1)
Range(xPin & ":" & xPfi).Select
ActiveSheet.Shapes.AddChart2(5, xlPareto).Select
ActiveChart.Parent.Name = "4Q Pareto"
ActiveSheet.ChartObjects("4Q Pareto").Activate
ActiveWindow.SmallScroll Down:=-9
ActiveSheet.Shapes("4Q Pareto").IncrementLeft 168
ActiveSheet.Shapes("4Q Pareto").IncrementTop -134.25
ActiveWindow.SmallScroll Down:=-6
ActiveSheet.Shapes("4Q Pareto").IncrementLeft -12.75
ActiveSheet.Shapes("4Q Pareto").IncrementTop -122.25
ActiveSheet.Shapes("4Q Pareto").Chart.HasTitle = True
ActiveSheet.Shapes("4Q Pareto").TextFrame2.TextRange.Characters.Text = "LATE - Root Cause"
ActiveSheet.Shapes("4Q Pareto").TextFrame2.TextRange.Characters(1, 17).ParagraphFormat.Alignment = msoAlignCenter
With ActiveSheet.Shapes("4Q Pareto").TextFrame2.TextRange.Characters(1, 17).Font
.BaselineOffset = 0
.Bold = msoFalse
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(89, 89, 89)
.Fill.Transparency = 0
.Fill.Solid
.Size = 14
.Italic = msoFalse
.Kerning = 12
.Name = "Calibri"
.UnderlineStyle = msoNoUnderline
.Spacing = 0
.Strike = msoNoStrike
End With
Range("N21").Select
ActiveWindow.SmallScroll Down:=15
Range("C25").Select
ActiveWindow.SmallScroll Down:=-12
ActiveSheet.Shapes.Range(Array("4Q Pareto")).Select
ActiveWindow.SmallScroll Down:=6
ActiveChart.SetSourceData Source:=Range("'4Q Report'!$C$26:$G$&xcL2")
Range("N21").Select
ActiveWindow.SmallScroll Down:=-12
End Sub
Thanks in advanced...
Tadeu