?
Solved

Retrieving chart numbers where category names are non-numeric

Posted on 2011-09-28
6
Medium Priority
?
278 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 1800 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 200 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
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…

862 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