Solved

Retrieving chart numbers where category names are non-numeric

Posted on 2011-09-28
6
269 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

696 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