Public & Private Function

Forestq

Active Member
Joined
May 9, 2010
Messages
482
Team,

how can I call this macro (I would like to assing to shape in sheet, but now I don't see it):

Code:
Public Sub CreateAChart(my_source As Range, my_location As ChartObject)
   Dim co As ChartObject
   Set co = my_location
   co.Chart.ChartType = xlLine 'xlPie
 
   co.Name = "ChartExample"
 
   co.Chart.SeriesCollection.Add Source:=my_source, Rowcol:=xlColumns, SeriesLabels:=True, Categorylabels:=True 
 
    With co.Chart
        .HasAxis(xlCategory, xlPrimary) = True
        .HasAxis(xlCategory, xlSecondary) = False
        .HasAxis(xlValue, xlPrimary) = True
        .HasAxis(xlValue, xlSecondary) = False
    End With
 
    With co.Chart.Axes(xlCategory)
        .HasTitle = True
        .AxisTitle.Caption = "Types"
        .AxisTitle.Border.Weight = xlMedium
    End With
 
    With co.Chart.Axes(xlValue)
        .HasTitle = True
 
        With .AxisTitle
            .Caption = "Quantity for 1999"
            .Font.Size = 8
            .Orientation = xlHorizontal
            .Characters(14, 4).Font.Italic = True
            .Border.Weight = xlMedium
        End With
    End With
    co.Chart.Axes(xlCategory).CategoryNames = _
    Array("a", "b", "c", "d", "e")
 
    co.Chart.Axes(xlValue).CrossesAt = 50
    co.Chart.Axes(xlValue).HasMajorGridlines = True 'pozioma
    co.Chart.Axes(xlCategory).HasMajorGridlines = False 'pionowa
 
    co.Chart.Axes(xlCategory).MajorTickMark = xlTickMarkCross
    co.Chart.Axes(xlCategory).TickLabelPosition = _
        xlTickLabelPositionNextToAxis
 
    co.Chart.ChartArea.Interior.Color = RGB(255, 255, 255)
 
    co.Chart.PlotArea.Interior.ColorIndex = 15
 
    With co.Chart.Legend.LegendEntries(1).LegendKey
         .Border.Weight = xlThick
    End With
 
   With co.Chart.SeriesCollection(1)
        .MarkerSize = 10
        .MarkerStyle = xlMarkerStyleDiamond
    With .Points(2)
        .MarkerSize = 20
        .MarkerStyle = xlMarkerStyleCircle
    End With
   End With
 
 
End Sub
 
Private Sub do_chart_5()
Dim my_source As Range
Dim my_location As ChartObject
 
Set my_source = Worksheets("Sheet1").Range("A1:D6")
 
Set my_location = Worksheets("Sheet3").ChartObjects.Add(100, 100, 400, 300)
 
Call CreateAChart(my_source, my_location)
 
End Sub

If all code is placed as:

Code:
Function CreateAChart(my_source As Range, my_location As ChartObject)
...
..
.
End Function
 
Sub do_chart_4()
...
..
.
End Sub

I see it and can assing "do_chart_4" to for example shape1.

Please give me advise or any comment how do resolve problem,

king regards,
PvK
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
If you're talking about the F8 macro window, subs don't show up in this if they require arguments, as there is no mechanism to provide them. You'd have to script a calling sub that had no args itself but called the actual sub with the args you needed.
 
Upvote 0

Forum statistics

Threads
1,224,517
Messages
6,179,237
Members
452,898
Latest member
Capolavoro009

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