Results 1 to 3 of 3

Attempting to change source data in Excel of a chart in PowerPoint

Threaded View

  1. #1
    Registered User
    Join Date
    04-17-2013
    Location
    St. Louis
    MS-Off Ver
    Excel 2010
    Posts
    36

    Attempting to change source data in Excel of a chart in PowerPoint

    Hi y'all. I'm trying to manipulate a chart in PowerPoint that has source data in Excel. To start off, the chart is a simple Hi-Low-Close stock chart that has six categories along the X axis. What I want to do is be able to edit the chart to give it an additional five categories along the X axis for a total of 11. Here's the relevant part of the code I've got now. The chart named "Chart7" on slide 2 of the PowerPoint presentation is the one I want to change. What I want to do is be able to press a button in PowerPoint named "1" and the chart will add in 5 more categories (This Quarter 1, This Half Year 1, etc) along the X axis. It's okay that they'd have no values right now.

    I know there's some redundancy with the first six lines of the ChartManip sub, but if I don't have that there, nothing changes when I press the button. When I do have it there like shown in the code below, nothing happens the first time I press it. The second time I press it though, it edits the data in Excel, but it only makes the chart data H36:K45 instead of H36:K46 like it says it should, so I think that's the line that's not working. I'll mark that in the code in red. I think the reason that it's only going through K45 is because the way I'm adding in the new categories in the X axis, I want them in between the ones that already exist. So it's automatically adjusting the source data already except that it's not capturing the new "Three Years 1" category I'm adding at the very end. The part with all the cutting is just adjusting the cells in Excel, so I don't think there should be a problem there. Eventually, I'll put in a shape named "2" that you can press to undo the new X axis categories, but I think I can figure that out once I know how to put them there in the first place. Any help would be greatly appreciated!

    Sub Test(oshp As Shape)
    
    Dim myChart As Chart
    Dim myChartData As ChartData
    Dim gWorkBook As Excel.Workbook
    Dim gWorkSheet As Excel.Worksheet
    
    Set myChart = ActivePresentation.Slides(2).Shapes("Chart7").Chart
    Set myChartData = myChart.ChartData
    myChartData.Activate
    Set gWorkBook = myChart.ChartData.Workbook
    Set gWorkSheet = gWorkBook.Worksheets(1)
    gWorkSheet.Application.ScreenUpdating = False
    
    If oshp.Name = "1" Then
    ChartManip
    End If
    
    If oshp.Name = "2" Then
    EndChartManip
    End If
    
    gWorkBook.Save
    gWorkBook.Close
    myChartData.Activate
    Set gWorkSheet = Nothing
    Set gWorkBook = Nothing
    Set myChartData = Nothing
    Set myChart = Nothing
    ActivePresentation.Application.Activate
    ActivePresentation.SlideShowSettings.Run
    
    End Sub
    
    Public Sub ChartManip()
    
    Set myChart = ActivePresentation.Slides(2).Shapes("Chart7").Chart
    Set myChartData = myChart.ChartData
    myChartData.Activate
    Set gWorkBook = myChart.ChartData.Workbook
    Set gWorkSheet = gWorkBook.Worksheets(1)
    gWorkSheet.Application.ScreenUpdating = False
    gWorkSheet.Range("H38:K41").Select
    Selection.Cut Destination:=gWorkSheet.Range("H39:K42")
    gWorkSheet.Range("H40:K42").Select
    Selection.Cut Destination:=gWorkSheet.Range("H41:K43")
    gWorkSheet.Range("H42:K43").Select
    Selection.Cut Destination:=gWorkSheet.Range("H43:K44")
    gWorkSheet.Range("H44:K44").Select
    Selection.Cut Destination:=gWorkSheet.Range("H45:K45")
    gWorkSheet.Range("H38").Select
    ActiveCell.FormulaR1C1 = "This Quarter 1"
    gWorkSheet.Range("H40").Select
    ActiveCell.FormulaR1C1 = "This Half Year 1"
    gWorkSheet.Range("H42").Select
    ActiveCell.FormulaR1C1 = "This Year 1"
    gWorkSheet.Range("H44").Select
    ActiveCell.FormulaR1C1 = "Two Years 1"
    gWorkSheet.Range("H46").Select
    ActiveCell.FormulaR1C1 = "Three Years 1"
    myChart.SetSourceData Source:=gWorkSheet.Range("H36:K46")
    
    End Sub
    Edit: I think the line in red is doing something actually, but no matter what, it never goes past H36:K45.
    Last edited by DPWM; 07-06-2013 at 10:12 PM.

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