Solved

Retrieving chart numbers where category names are non-numeric

Posted on 2011-09-28
6
268 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

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…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

738 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