Results 1 to 2 of 2

Thread: updating row source for charts in VBA [RESOLVED]

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2002
    Location
    Glasgow, Scotland
    Posts
    202

    Resolved updating row source for charts in VBA [RESOLVED]

    ok,

    i have a selection of charts on a spreadsheet.

    e.g. charts(1) to charts(12)

    i have a combo box which has numbers 1 to 52, for each week of the month.

    I want the charts row source to be updated when a week is selected from the drop down. I dont want to change the column or source sheet, just the rows.

    is there any easy way to do this? or will i have to read the current source into a string and manipulate it?

    i was messing about with this:
    [2nd Edit to incorporate both chart plots]
    VB Code:
    1. For MyCount = 1 To 12
    2.     Charts(MyCount).SeriesCollection(1).SourceData Source:=Sheets(1).Range("a1:a10"), _
    3.     PlotBy:=xlColumns
    4.     Charts(MyCount).SeriesCollection(2).SourceData Source:=Sheets(1).Range("a1:a10"), _
    5.     PlotBy:=xlColumns
    6. Next
    [EDIT]
    just adding my calculations to get start and end rows for selected week:
    VB Code:
    1. If SelectedWeek = 1 Then
    2.     StartRow = 3
    3.     EndRow = 9
    4.     Else
    5.         StartRow = ((SelectedWeek * 6) + 3) - 6
    6.         EndRow = (SelectedWeek * 6) + 3
    7. End If

    all i want to update in the above code is 1 and 10 row references.
    each chart has different source columns, but the same source rows so i dont want to hard code the range for each chart.

    TIA
    Last edited by Br1an_g; Apr 12th, 2005 at 10:41 AM. Reason: resolved
    if you fail to plan, you plan to fail

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Jan 2002
    Location
    Glasgow, Scotland
    Posts
    202

    Re: updating row source for charts in VBA

    ok, so couldnt figure it out, so i took another approach.

    I set the graphs source to incorporate the complete range of data.

    I then created a macro to hide the rows that were outwith the week that had been selected.

    this has the effect of updating the graphs which only show visible data.
    VB Code:
    1. 'assign start and end rows for selected week
    2. StartRow = (SelectedWeek * 8) - (2 + SelectedWeek)
    3. EndRow = StartRow + 8
    4.  
    5. 'update row source for charts
    6.     'first select source sheets
    7.     Sheets("Sheet1").Activate
    8.     ActiveSheet.Cells.Select
    9.     Selection.EntireRow.Hidden = False
    10.    
    11.     'hide all but current weekly rows
    12.     ActiveSheet.Range("4:" & StartRow & "," & EndRow & ":368").Select
    13.     Selection.EntireRow.Hidden = True
    14.    
    15.     Sheets("Sheet2").Activate
    16.     ActiveSheet.Cells.Select
    17.     Selection.EntireRow.Hidden = False
    18.    
    19.     'hide all but current weekly rows
    20.     ActiveSheet.Range("4:" & StartRow & "," & EndRow & ":368").Select
    21.     Selection.EntireRow.Hidden = True
    22.    
    23. Application.ScreenUpdating = True
    24.  
    25. 'activate graphs sheet
    26. Worksheets("Graphs").Activate

    bit messy but im still working on it
    [EDIT] updated code
    Last edited by Br1an_g; Apr 12th, 2005 at 10:42 AM.
    if you fail to plan, you plan to fail

Posting Permissions

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



Click Here to Expand Forum to Full Width