I need help for excel chart vba codigo

Wellington

New Member
Joined
Oct 7, 2002
Messages
4
I need help to do a macro to get to generate a graph of the personalized type, with lines - columns in 2 axes.
below it follows part of the macro that I arranged, more it doesn't work

I believe that the problem is in that line
'ObjExcel.activechart.ChartType = 97
ObjExcel.ActiveChart.ApplyCustomType 22, "SentinalColorLineChart"




'Create Object
Set ObjExcel = CreateObject("Excel.Sheet")
set x = createobject("Excel.sheet")


'show or dont show excel to user, TRUE or FALSE
ObjExcel.Application.Visible = True

' populate the cells
ObjExcel.ActiveSheet.Range("B2:k2").Value = Array("Week1", "Week2", "Week3", "Week4", "Week5", "Week6", "Week7", "Week8", "Week9", "Week10")
ObjExcel.ActiveSheet.Range("B3:k3").Value = Array("67", "87", "5", "9", "7", "45", "45", "54", "54", "10")
ObjExcel.ActiveSheet.Range("B4:k4").Value = Array("10", "10", "8", "27", "33", "37", "50", "54", "10", "10")
ObjExcel.ActiveSheet.Range("B5:k5").Value = Array("23", "3", "86", "64", "60", "18", "5", "1", "36", "80")
ObjExcel.ActiveSheet.Cells(3,1).Value="Internet Explorer"
ObjExcel.ActiveSheet.Cells(4,1).Value="Netscape"
ObjExcel.ActiveSheet.Cells(5,1).Value="Other"

' Select the contents that need to be in the chart
ObjExcel.ActiveSheet.Range("b2:k5").Select

' Add the chart
ObjExcel.Charts.Add
' Format the chart, set type of chart, shape of the bars, show title, get the data for the chart, show datatable, show legend

'ObjExcel.activechart.ChartType = 97
ObjExcel.ActiveChart.ApplyCustomType 22, "SentinalColorLineChart"

'xlLineMarkers
ObjExcel.activechart.BarShape = 3
ObjExcel.activechart.HasTitle = True
ObjExcel.activechart.ChartTitle.Text = "Teste"
'ObjExcel.activechart.SetSourceData
'ObjExcel.Sheets("Sheet1").Range("A1:k5"),1
ObjExcel.activechart.Location 1
ObjExcel.activechart.HasDataTable = True
'ObjExcel.activechart.DataTable.ShowLegendKey = True
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
The ActiveChart property applies to Application, Window or WorkBook objects. Your ObjExcel object is a Worksheet object, so the code fails.

Set a reference to the workbook, like this:

Set ObjWB - ObjExcel.Parent

Then use ActiveChart with ObjWB.
 

Wellington

New Member
Joined
Oct 7, 2002
Messages
4
When I type is line the following mistake returns

Set ObjWb = CreateObject("Excel.Workbook")
ActiveX component can´t create object



I think the mistake is in the line below:
ObjExcel.ActiveChart.ApplyCustomType 22, "Line - Column on 2 axes"

Because when I put any other type he generates the graph usually
Example: this work

ObjExcel.ActiveChart.ApplyCustomType 97
 

Wellington

New Member
Joined
Oct 7, 2002
Messages
4

ADVERTISEMENT

Any one of the three of the mistake
21,22,23

Will it be that I am wandering in the name of the graph, what cannot exist?
"Line - Column on 2 axes"
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
When I record it it is:

"Line - Column on 2 Axes"

Note the capital A in Axes. Maybe it makes a difference.
 

Wellington

New Member
Joined
Oct 7, 2002
Messages
4
I thank for the help, I managed to do to work, it was really the name of the graph that it was wrong. Thank you
 

Forum statistics

Threads
1,144,118
Messages
5,722,587
Members
422,447
Latest member
knopp

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
Top