Solved

VBA to check if charttype is 3D

Posted on 2011-09-05
4
393 Views
Last Modified: 2012-05-12
Hi Experts

I want to create a macro that checks if the chart a user has created is in 3D - I know there is a chartype property of chart, but this returns a number, does anyone have a list of numbers or is there a simpler way  -
currently I have

If InStr(UCase(mcht.ChartType), "3D") > 0 Then
       
            MsgBox "3D"
        End If
       
but as the charttpe is a number its not working, when selecting a charttype I can type in text
0
Comment
Question by:MrDavidThorn
  • 2
4 Comments
 
LVL 15

Expert Comment

by:CSLARSEN
ID: 36485093
Hi
You can check for the number in chart type.

Check a list of chartypes, e.g. http://it.toolbox.com/wiki/index.php/EXCEL_Chart_Type_Enumeration
Another more complete but also less elegant would be to insert all 3D numbers in an array to validate the selected charttype against.
However from my point of view you are not using a poor proxy for 3D identification.
Cheers
cslarsen
0
 
LVL 81

Accepted Solution

by:
byundt earned 500 total points
ID: 36485124
Here is a function that incorporates the numbers suggested by CSLARSEN. It returns TRUE if the ChartType is one of the 3D types. Install it in a regular module, or incorporate the logic in your sub.

Function IsChart3D(co As ChartObject) As Boolean
Select Case co.Chart.ChartType
Case -4102 To -4100, -4098, 54 To 56, 60 To 62, 78 To 79
    IsChart3D = True
End Select
End Function

Open in new window

0
 
LVL 15

Expert Comment

by:CSLARSEN
ID: 36485406
Nice one byundt
learned the compact array/case part
thx carsten
0
 

Author Closing Comment

by:MrDavidThorn
ID: 36485466
thanks guys
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
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…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

821 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