Solved

Retrieving chart numbers where category names are non-numeric

Posted on 2011-09-28
6
248 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
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.

 

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

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
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 Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

910 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

22 Experts available now in Live!

Get 1:1 Help Now