+ Reply to Thread
Results 1 to 2 of 2

vba code to create chart and fix the axis of the chart

Hybrid View

  1. #1
    Registered User
    Join Date
    09-25-2012
    Location
    Gurgaon
    MS-Off Ver
    Excel 2007
    Posts
    25

    vba code to create chart and fix the axis of the chart

    Hi All,

    i am creating chart with the help of macro.
    every time data changes( values and number of rows and columns)
    whenever there is less then 3 row data chart changes its axis, and i have to switch row/column.
    Please help how to get rid of this problem.
    Below is the code
    Sub Chart()
    Dim R As Integer
    
    Dim rngChtData As Range
    Dim rngChtXVal As Range
         
         Range("L2").Select
        Range(Selection, Selection.End(xlDown)).Select
        Range(Selection, Selection.End(xlToRight)).Select
        Set rngChtData = Selection
        With rngChtData
            Set rngChtXVal = .Columns(1).Offset(1).Resize(.Rows.Count - 1)
        End With
        
        ActiveSheet.Shapes.AddChart.Select
        
         ActiveChart.SeriesCollection(1).Select
        ActiveChart.ChartType = xlCylinderColStacked
        ActiveSheet.ChartObjects("Chart 1").Activate
        ActiveChart.SeriesCollection(1).ApplyDataLabels
        ActiveSheet.ChartObjects("Chart 1").Activate
       ActiveChart.SeriesCollection(2).Select
        ActiveChart.SeriesCollection(1).Interior.Color = RGB(0, 153, 64)
        ActiveSheet.ChartObjects("Chart 1").Activate
        ActiveChart.SeriesCollection(2).ApplyDataLabels
        ActiveSheet.ChartObjects("Chart 1").Activate
        ActiveChart.SeriesCollection(1).Select
        ActiveSheet.ChartObjects("Chart 1").Activate
        ActiveSheet.ChartObjects("Chart 1").Activate
        ActiveChart.PlotArea.Select
        Selection.ClearFormats
        ActiveSheet.ChartObjects("Chart 1").Activate
        ActiveSheet.ChartObjects("Chart 1").Activate
        
        ActiveSheet.ChartObjects("Chart 1").Activate
        ActiveChart.Axes(xlValue).MajorGridlines.Select
        Selection.Delete
        ActiveChart.Axes(xlValue).Select
        ActiveSheet.ChartObjects("Chart 1").Activate
        ActiveChart.Axes(xlValue).MinimumScale = 0
        ActiveSheet.ChartObjects("Chart 1").Chart.Export C

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: vba code to create chart and fix the axis of the chart

    Take a look at the PlotBy method.

        ActiveChart.PlotBy = xlColumns
    xlRows is the other alternative.
    Cheers
    Andy
    www.andypope.info

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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