Solved

How to change chart titles and axis VB.Net Excel Charting

Posted on 2012-03-28
2
655 Views
Last Modified: 2012-03-28
I have created a simple chart in a worksheet and need to change the default axis titles but have a problem with syntax.
	
With objChart

   .Name = "Turnover Chart"
   .SetSourceData(Source:=objRange1, PlotBy:=Excel.XlRowCol.xlColumns)
   .ChartType = Excel.XlChartType.xlCylinderColStacked
   .Location(Where:=Excel.XlChartLocation.xlLocationAsObject, Name:="Chart")

   ' THE NEXT LINE THROWS AN EXCEPTION
   objAxis = CType(.Axes(Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlPrimary), Excel.Axis)

   With objAxis
       .HasTitle = True
       .AxisTitle.Text = "Sales"
   End With

End With

Open in new window

0
Comment
Question by:TeDeSm
2 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 37775853
I think the Location line is the problem as it actually returns a new reference to the chart object, so:
With objChart

   .Name = "Turnover Chart"
   .SetSourceData(Source:=objRange1, PlotBy:=Excel.XlRowCol.xlColumns)
   .ChartType = Excel.XlChartType.xlCylinderColStacked
End With
  objChart = objChart.Location(Where:=Excel.XlChartLocation.xlLocationAsObject, Name:="Chart")
With objChart
   ' THE NEXT LINE THROWS AN EXCEPTION
   objAxis = CType(.Axes(Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlPrimary), Excel.Axis)

   With objAxis
       .HasTitle = True
       .AxisTitle.Text = "Sales"
   End With

End With

Open in new window

0
 

Author Closing Comment

by:TeDeSm
ID: 37776091
I had figured that I had lost the reference to the chart, just couldn't figure out where'

A spot on solution.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now