+ Reply to Thread
Results 1 to 2 of 2

Is this the fastest way to do it?

  1. #1
    Registered User
    Join Date
    06-09-2004
    Posts
    14

    Is this the fastest way to do it?

    Hi all of you,

    I have around 9 charts in my workbook and a sheet with 9 embedded charts. I am varying parameters and noting the variation in these charts. The problem is when I change a parameter, I use macro code to update all the axes. But the following code is very slow. It seems to me that updating the embedded charts takes much longer since if I comment out that portion of the code, the changes are pretty fast. What are the ways to speed this thing up? Any help is greatly appreciated.

    Regards,
    Ram

    ''' Update the 9 charts
    Dim shVs_x As Sheets ''' charts with 'x' (length) on x axis
    Dim ch As Chart
    Set shVs_x = Sheets(Array(1, 2, 3, 4, 5, 6, 7, 8, 9)) ''' collection of charts to be updated
    For Each ch In shVs_x
    With ch.Axes(xlCategory)
    .MinimumScale = minval
    .MaximumScale = maxval
    End With
    Next ch
    ''' Update the embedded charts
    Dim chO As ChartObject
    For Each chO In wsPlots.ChartObjects
    With chO.Chart.Axes(xlCategory)
    .MinimumScale = minval
    .MaximumScale = maxval
    End With
    Next chO

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Ram,

    I have made some changes to the code that should speed things up a little. I am not sure way you put the Sheets into a Variable Array. The Sheets are a collection object that can accessed by their index value within the collection.
    _________________________________________________________________

    ''' Update the 9 charts

    Dim shVs_x As Sheets ''' charts with 'x' (length) on x axis
    Dim ch As Chart
    Dim I As Long

    Application.ScreenUpdating = False

    For I = 1 To 9
    Set shVs_x= Sheets(I)
    Set ch = shVs_x.Chart(1)
    With ch.Axes(xlCategory)
    .MinimumScale = minval
    .MaximumScale = maxval
    End With
    Next I


    ''' Update the embedded charts

    Dim chO As ChartObject
    For Each chO In wsPlots.ChartObjects
    With chO.Chart.Axes(xlCategory)
    .MinimumScale = minval
    .MaximumScale = maxval
    End With
    Next chO

    Application.ScreenUpdating = True

    _________________________________________________________________

    Hope this helps,
    Leith Ross

+ 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