allstarrunner
New Member
- Joined
- May 29, 2012
- Messages
- 34
Hi, there are lots of threads out there about this error (424), but I am not well versed enough in VBA yet to convert their problem and solution to my code, so I am hoping someone here can help me out.
When I run the macro by itself, it works fine; but as soon as I try to call this macro in another one of my macro's, it gives me the "object required" macro. Can someone smarter than I see what is going wrong? Also, I'm sure this code is not very efficient, so I apologize if it offends your sense of efficient vba code writing Thanks!
When I run the macro by itself, it works fine; but as soon as I try to call this macro in another one of my macro's, it gives me the "object required" macro. Can someone smarter than I see what is going wrong? Also, I'm sure this code is not very efficient, so I apologize if it offends your sense of efficient vba code writing Thanks!
Code:
'Create and Define range for bar graph
Dim limitUM As Double
Dim p, ct, cl As Long
'Name the Range "limit"
Range("S1").Select
ActiveCell.FormulaR1C1 = "94%"
ActiveWorkbook.Names.Add Name:="limitUMN", RefersToR1C1:="='UM Analysis'!R1C19"
ActiveWorkbook.Names("limitUMN").Comment = ""
ActiveWorkbook.Names.Add Name:="limitUMN2", RefersToR1C1:="='UM Analysis'!R1C19"
ActiveWorkbook.Names("limitUMN2").Comment = ""
ActiveWorkbook.Names.Add Name:="limitUMN3", RefersToR1C1:="='UM Analysis'!R1C19"
ActiveWorkbook.Names("limitUMN3").Comment = ""
ActiveWorkbook.Names.Add Name:="limitUMN4", RefersToR1C1:="='UM Analysis'!R1C19"
ActiveWorkbook.Names("limitUMN4").Comment = ""
limitUM = Range("limitUMN").Value ' 94%
limitUM2 = Range("limitUMN2").Value
limitUM3 = Range("limitUMN3").Value
limitUM4 = Range("limitUMN4").Value
p = 2
ct = 2
cl = 2
ct = 2
Do While Application.WorksheetFunction.Sum(Range("F3:F" & p)) < limitUM
p = p + 1
Loop
Range("D3:E" & p).Name = "RangeUM"
'Add Chart 1
With Sheets("UM Analysis").ChartObjects.Add _
(Left:=200, Width:=275, Top:=350, Height:=325)
.Name = "Chart1"
With .Chart
.SetSourceData Source:=Sheets("UM Analysis").Range("RangeUM")
.ApplyChartTemplate ( _
"C:\Users\name\AppData\Roaming\Microsoft\Templates\Charts\StackedBoxBlue.crtx" _
)
.HasTitle = True
.ChartTitle.Text = "1 Unit UM Breakdown"
.PlotBy = xlRows
For i = 1 To .SeriesCollection.Count
.SeriesCollection(i).Interior.Color = Sheets("UM Analysis").Range("T" & i).Interior.Color
.SeriesCollection(i).Border.ColorIndex = 1
.SeriesCollection(i).Border.Weight = 1
.SeriesCollection(i).DataLabels.ShowSeriesName = True
.SeriesCollection(i).DataLabels.ShowValue = True
.SeriesCollection(i).DataLabels.Format.TextFrame2.TextRange.Font.Bold = True
Next i
End With
End With
Do While Application.WorksheetFunction.Sum(Range("I3:I" & ct)) < limitUM2
ct = ct + 1
Loop
Range("G3:H" & ct).Name = "RangeUM2"
'Add Chart 2
With Sheets("UM Analysis").ChartObjects.Add _
(Left:=200, Width:=275, Top:=675, Height:=325)
.Name = "Chart2"
With .Chart
.SetSourceData Source:=Sheets("UM Analysis").Range("RangeUM2")
.ApplyChartTemplate ( _
"C:\Users\name\AppData\Roaming\Microsoft\Templates\Charts\StackedBoxBlue.crtx" _
)
.HasTitle = True
.ChartTitle.Text = "2 Unit UM Breakdown"
.PlotBy = xlRows
For j = 1 To .SeriesCollection.Count
.SeriesCollection(j).Interior.Color = Sheets("UM Analysis").Range("U" & j).Interior.Color
.SeriesCollection(j).Border.ColorIndex = 1
.SeriesCollection(j).Border.Weight = 1
.SeriesCollection(j).DataLabels.ShowSeriesName = True
.SeriesCollection(j).DataLabels.ShowValue = True
.SeriesCollection(j).DataLabels.Format.TextFrame2.TextRange.Font.Bold = True
Next j
End With
End With
Do While Application.WorksheetFunction.Sum(Range("N3:N" & cl)) < limitUM3
cl = cl + 1
Loop
'Add Chart 3 (edit)
'Dim lMaxRow As Long
lMaxRow = Sheets("UM Analysis").Range("E100").End(xlUp).Row
With Sheets("UM Analysis").ChartObjects.Add(Left:=200, Width:=275, Top:=1000, Height:=325)
.Name = "MyChart"
With .Chart
.SetSourceData Source:=Union(Sheets("Um Analysis").Range("J3:J" & cl), Sheets("UM Analysis").Range("M3:M" & cl))
.ApplyChartTemplate ( _
"C:\Users\name\AppData\Roaming\Microsoft\Templates\Charts\StackedBoxBlue.crtx" _
)
.HasTitle = True
.ChartTitle.Text = "3 & 4 Unit UM Breakdown"
.PlotBy = xlRows
For k = 1 To .SeriesCollection.Count
.SeriesCollection(k).Interior.Color = Sheets("UM Analysis").Range("V" & k).Interior.Color
.SeriesCollection(k).Border.ColorIndex = 1
.SeriesCollection(k).Border.Weight = 1
.SeriesCollection(k).DataLabels.ShowSeriesName = True
.SeriesCollection(k).DataLabels.ShowValue = True
.SeriesCollection(k).DataLabels.Format.TextFrame2.TextRange.Font.Bold = True
Next k
End With
End With
Do While Application.WorksheetFunction.Sum(Range("Q3:Q" & ct)) < limitUM
ct = ct + 1
Loop
Range("O3:P" & p).Name = "RangeUM3"
'Add Chart 4
With Sheets("UM Analysis").ChartObjects.Add _
(Left:=200, Width:=275, Top:=1325, Height:=325)
.Name = "Chart1"
With .Chart
.SetSourceData Source:=Sheets("UM Analysis").Range("RangeUM3")
.ApplyChartTemplate ( _
"C:\Users\Name\AppData\Roaming\Microsoft\Templates\Charts\StackedBoxBlue.crtx" _
)
.HasTitle = True
.ChartTitle.Text = "5 & Over UM Breakdown"
.PlotBy = xlRows
For m = 1 To .SeriesCollection.Count
'.SeriesCollection(m).Interior.Color = Sheets("UM Analysis").Range("T" & i).Interior.Color
.SeriesCollection(m).Border.ColorIndex = 1
.SeriesCollection(m).Border.Weight = 1
.SeriesCollection(m).DataLabels.ShowSeriesName = True
.SeriesCollection(m).DataLabels.ShowValue = True
.SeriesCollection(m).DataLabels.Format.TextFrame2.TextRange.Font.Bold = True
Next m
End With
End With
End Sub