Solved

Retrieving chart numbers where category names are non-numeric

Posted on 2011-09-28
6
237 Views
Last Modified: 2012-06-22
Dear Experts:

attached sample files shows several pie charts.

I wonder whether it is possible using VBA ....
... to retrieve the chart numbers of the charts where the category name is text (not numeric).
This applies for Chart No. 2 and Chart No. 7

I have attached a sample file for your convenience.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
 Retrieving-Chart-Numbers.xlsm
0
Comment
Question by:AndreasHermle
  • 3
  • 2
6 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 450 total points
ID: 36813164
For example:
Sub Test()
   Dim cht As Chart
   Dim ChtObj As ChartObject
   Dim varCats
   Dim strCharts As String
   For Each ChtObj In ActiveSheet.ChartObjects
      Set cht = ChtObj.Chart
      varCats = cht.SeriesCollection(1).XValues
      If IsNumeric(varCats(1)) Then
         strCharts = strCharts & ", " & ChtObj.Name
      End If
   Next ChtObj
   msgbox Mid$(strCharts, 3)
End Sub

Open in new window


Notes:
1. This returns the name of the parent ChartObject rather than the chart as that is probably more useful.
2. It only test the first category value - could be altered to check all of them for numbers if required.

HTH
Rory
0
 
LVL 9

Assisted Solution

by:Ramanhp
Ramanhp earned 50 total points
ID: 36813761
above is great, just a small correction >>       If Not IsNumeric(varCats(1)) Then


Sub Test1()
   Dim cht As Chart
   Dim ChtObj As ChartObject
   Dim varCats
   Dim strCharts As String
   For Each ChtObj In ActiveSheet.ChartObjects
      Set cht = ChtObj.Chart
      varCats = cht.SeriesCollection(1).XValues
       
     
      If Not IsNumeric(varCats(1)) Then
         strCharts = strCharts & ", " & ChtObj.Name
      End If
   Next ChtObj
   MsgBox Mid$(strCharts, 3)
End Sub
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 36813820
Oh yes - thanks. (misread the question) :)
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:AndreasHermle
ID: 36814848
HI rorya and ramanhp:

great works like a charm. Thank you very much for your great/professional support.

As a matter of fact I also would like to know how the code would look like if just/simply the chart number  is returned instead of the name of the parent ChartObject.

Regards, Andreas
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 36814900
Change line 10 to:
strCharts = strCharts & ", " & Cht.Index

Open in new window

0
 

Author Closing Comment

by:AndreasHermle
ID: 36815575
Thank you very much for your superb and swift support.

Regards, Andreas
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

A2 = A1 That kind of cell reference is relative.  If you copy it from A2 to B2, then B2 will get this: B2 = B1 That's all fine and good, but if you then insert a new row above row 2, you'll find: A3 = A1 B3 = B1 This is intentional. …
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
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…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

743 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

13 Experts available now in Live!

Get 1:1 Help Now