Object Requred when calling macro

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!

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
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
The code you posted doesn't have a Sub line. Can you give an example of how you call it from another procedure?
 
Upvote 0
as I was writing out my response to you, I had an idea, and I tried it, and it worked! So thank you for taking my brain there!

this was the line it was erroring out on in a different macro (the one I was trying to run the macro for the code above):

Code:
Application.Run "PERSONAL.XLSB!UMCharts_DeepDive"

Then I added:
Code:
ThisWorkbook.Application.Run "PERSONAL.XLSB!UMCharts_DeepDive"

And it worked.
 
Upvote 0
Although I don't honestly understand the logic behind it...I've called other macro's before and never needed to put "ThisWorkbook" in front of it?

For instance, the line right in front of it is:

Code:
Application.Run "PERSONAL.XLSB!Colors_UMAnalysis"
       
ThisWorkbook.Application.Run "PERSONAL.XLSB!UMCharts_DeepDive"

The first macro run's just fine without the "ThisWorkbook"; is that because the first macro (Colors_UMAnalysis) has no variabls or objects in it? It is basically just adding colors to certain places....
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top