+ Reply to Thread
Results 1 to 3 of 3

vba to switch columns to rows in a line chart

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-13-2009
    Location
    New Jersey
    MS-Off Ver
    Excel 2007
    Posts
    136

    vba to switch columns to rows in a line chart

    I have the following code:

    Set Chart1 = ActiveSheet.ChartObjects.Add _
        (Left:=0, Width:=700, Top:=0, Height:=180)
        
        Chart1.Chart.SetSourceData Source:=MC.Range(MC.Cells(1, 1), MC.Cells(255, iYears))
        Chart1.Chart.ChartType = xlLine
        Chart1.Activate
    The problem is that each series is in a row but it seems to think that the series data are in columns. I know that manually I can right click the chart, select "Select Data" and click on the "Switch Row/Column" button to fix it but I can't figure out how to do this in code. The macro recorder was no help as it only gave me this when I ran through the sequence manually.

    Sub Macro1()
    '
    ' Macro1 Macro
    '
    ' Keyboard Shortcut: Ctrl+g
    '
        ActiveSheet.ChartObjects("Chart 1").Activate
        ActiveSheet.ChartObjects("Chart 1").Activate
        ActiveChart.SetSourceData
    End Sub
    Any help would be appreciated!
    Last edited by jerseyguy1996; 11-05-2009 at 01:27 PM.

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

    Re: vba to switch columns to rows in a line chart

    untested

        Chart1.Chart.plotby = xlColumns  ' or xlRows
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Contributor
    Join Date
    03-13-2009
    Location
    New Jersey
    MS-Off Ver
    Excel 2007
    Posts
    136

    Re: vba to switch columns to rows in a line chart

    Quote Originally Posted by Andy Pope View Post
    untested

        Chart1.Chart.plotby = xlColumns  ' or xlRows
    That worked perfectly! Thanks!

+ 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