+ Reply to Thread
Results 1 to 3 of 3

Ignoring chart types with no axes for finding axes title

Hybrid View

  1. #1
    Registered User
    Join Date
    11-07-2012
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Office 365
    Posts
    71

    Lightbulb Ignoring chart types with no axes for finding axes title

    Hello all you Excel experts!

    Code below, problematic line marked with red.

    I am writing a piece of code to list the title, axis titles onto a list for further programming.

    I have run into a weird little problem. In my IF statement to see if the active chart has an axis title, the program fails if the chart type is one where axes are not applicable. I encountered this problem when the program came across a 3D pie chart.

    I have tried including HasAxis (I think it is called) in the IF statement, but still had the error.

    The solution I have made is to make a parent IF statement where I repeatedly use IF chart.type <> [type] for all the chart types I can think of that do not use axes. This solution works, but is not really elegant or sure. I have definitely left some out.

    I was thinking, is there a better way to do this? Simplified code below.

    For Each ws In Worksheets
            If ws.ChartObjects.Count > 0 Then
            For Each cht In ws.ChartObjects
                
                cht.Activate 'Activates the chart for changes
                  
                    '--- If the chart category axis has a title, it is written in the list
                If ActiveChart.ChartType <> xl3DPie And ActiveChart.ChartType <> xl3DPieExploded And ActiveChart.ChartType <> xlBarOfPie And xlBubble And ActiveChart.ChartType <> xlPie Then
                    
                    If ActiveChart.Axes(xlCategory).HasTitle = True Then
                     
                        Sheets("TransArrCharts").Cells(pasterow, 1) = ActiveChart.Axes(xlCategory).AxisTitle.Caption
                      
                        pasterow = pasterow + 1
                     
                    End If
                End If
                
            Next cht
            End If
        Next ws
    Thank you,


    GregersDK

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Ignoring chart types with no axes for finding axes title

    Hi,

    HasAxis should work to test for an axis with a 3D pie chart. What was the code you tried and what happened?
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Registered User
    Join Date
    11-07-2012
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Office 365
    Posts
    71

    Re: Ignoring chart types with no axes for finding axes title

    Hey, sorry for the late reply.

    That is totally true! My mistake was making an IF statement with HasAxis = True AND .Axes(xlCategory).HasTitle = True.

    The right method, of course was to first check .HasAxis before .HasTitle. Meaning it needs to be nested IF statements.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Label Chart Title & Axes
    By Apple1 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-03-2014, 09:14 AM
  2. Label Chart Axes & Title
    By Apple1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-02-2014, 11:11 PM
  3. Chart with two different y axes
    By n_ant in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 04-29-2013, 08:22 AM
  4. [SOLVED] Changing data types on Line/bar with two axes
    By rojo6964 in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 05-24-2006, 03:35 AM
  5. Having two X-axes on same chart
    By Boon8888 in forum Excel General
    Replies: 1
    Last Post: 03-23-2006, 04:55 PM
  6. [SOLVED] CHART AxES TITLE
    By yorkielover02 in forum Excel General
    Replies: 1
    Last Post: 02-03-2005, 06:06 PM
  7. plotting a chart title on 3 axes of a surface plot
    By gosetty in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-07-2005, 08:07 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1