+ Reply to Thread
Results 1 to 6 of 6

Removing focus from chart

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-31-2008
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    149

    Removing focus from chart

    Hi,

    I have a dashboard where I select a chart type, and then the selected chart is built via VBA.

    Although the source data changes, the code to create each chart is pretty much identical, apart from the chart's properties.

    After the chart is created, I'd prefer it if none of the charts elements were selected. To achieve this I'm using :-

    range("A1").select
    In all but 2 cases, this works, but for those 2 charts the chart's labels remain selected even after the code above is stepped over.

    Can anyone suggest a way to remove focus from my chart in every case once they have been fully created?

    Many thanks.
    Last edited by bd528; 12-10-2013 at 07:53 AM.

  2. #2
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Removing focus from chart

    You do not need to select the chart to begin with - perhaps if you remove that from the code your problem will be resolved?

  3. #3
    Forum Contributor
    Join Date
    12-31-2008
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Removing focus from chart

    You were right - I was selecting the labels. I removed the offending code, which solved my problem - in part. Now, on the same 2 graphs the chart area is now selected after the code has run. I believe this my be because I'm activating the area, as per below :-

           With chrt
                .ChartType = xl3DPie
                .SetSourceData Source:=Sheets("GraphData").Range("A2:B" & lastrow)
                .SetElement (msoElementLegendRight)
                .SetElement (msoElementDataLabelShow)
                .SetElement (msoElementDataLabelBestFit)
                .SetElement (msoElementChartTitleNone)
                .ChartTitle.Text = "Percentage of inv"
                .ChartArea.Format.ThreeD.RotationY = 50
                .ChartStyle = 26
            End With
            ActiveSheet.Shapes("Chart 1").Line.Visible = msoFalse
            ActiveSheet.ChartObjects("Chart 1").Activate
            ActiveChart.SeriesCollection(1).DataLabels.ShowPercentage = True
            ActiveChart.SeriesCollection(1).DataLabels.ShowSeriesName = False
            ActiveChart.SeriesCollection(1).DataLabels.ShowCategoryName = False
            ActiveChart.SeriesCollection(1).DataLabels.ShowValue = False
    I can't seem to find a way of changing the DataLabels properties without activating the chart.

    Is there a way of removing focus from the chart and setting it to cell A1?

  4. #4
    Forum Contributor
    Join Date
    12-31-2008
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Removing focus from chart

    As an update, I've noticed that if I manually step through the code, I can set focus to cell A1, but if I run the code in full, it seems to miss that step.

  5. #5
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Removing focus from chart

    If chrt is your chart object variable then you may use:
          With chrt
                .ChartType = xl3DPie
                .SetSourceData Source:=Sheets("GraphData").Range("A2:B" & lastrow)
                .SetElement (msoElementLegendRight)
                .SetElement (msoElementDataLabelShow)
                .SetElement (msoElementDataLabelBestFit)
                .SetElement (msoElementChartTitleNone)
                .ChartTitle.Text = "Percentage of inv"
                .ChartArea.Format.ThreeD.RotationY = 50
                .ChartStyle = 26
                 With .SeriesCollection(1).DataLabels
                    .ShowPercentage = True
                    .ShowSeriesName = False
                    .ShowCategoryName = False
                    .ShowValue = False
                End With
            End With

  6. #6
    Forum Contributor
    Join Date
    12-31-2008
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Removing focus from chart

    Quote Originally Posted by Izandol View Post
    If chrt is your chart object variable then you may use:
          With chrt
                .ChartType = xl3DPie
                .SetSourceData Source:=Sheets("GraphData").Range("A2:B" & lastrow)
                .SetElement (msoElementLegendRight)
                .SetElement (msoElementDataLabelShow)
                .SetElement (msoElementDataLabelBestFit)
                .SetElement (msoElementChartTitleNone)
                .ChartTitle.Text = "Percentage of inv"
                .ChartArea.Format.ThreeD.RotationY = 50
                .ChartStyle = 26
                 With .SeriesCollection(1).DataLabels
                    .ShowPercentage = True
                    .ShowSeriesName = False
                    .ShowCategoryName = False
                    .ShowValue = False
                End With
            End With
    Refined code, and now none of the chart is selected - thank you!

+ 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. removing 0% from pie chart
    By ratkiller in forum Excel General
    Replies: 1
    Last Post: 10-16-2012, 04:02 AM
  2. Removing a legend entry on a chart
    By q felt in forum Excel General
    Replies: 9
    Last Post: 05-31-2010, 07:08 PM
  3. removing data from a chart
    By neilpateluk in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 07-31-2009, 04:58 AM
  4. Removing links on chart
    By cuewoz in forum Excel Charting & Pivots
    Replies: 5
    Last Post: 08-11-2007, 10:19 PM
  5. [SOLVED] Removing a serie in a chart
    By Renaud in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 05-31-2005, 03:05 PM

Tags for this Thread

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