Results 1 to 8 of 8

Resize all charts on a worksheet.

Threaded View

  1. #1
    abhay_547
    Guest

    Resize all charts on a worksheet.

    Hi All,

    I have the below code which re-sizes all charts on a sheet with one's chart's size. I want to actually give the user a input option where user can enter the width and height in a inputbox and then macro will resize all charts on the sheet with the same size.

    Sub ResizeAndArrangeChartObjects()
    W = ActiveSheet.ChartObjects("Chart 1").Width
    H = ActiveSheet.ChartObjects("Chart 1").Height
    TopPos = 0
    For Each chtObj In ActiveSheet.ChartObjects
         With chtObj
                 .Width = W
                 .Height = H
                 .Left = 0
                 .Top = TopPos
         End With
         TopPos = TopPos + H
    Next chtObj
    End Sub

    'You refer to the chart object something like this:
    
         ActiveSheet.ChartObjects(1) ' the first chart object in the active sheet
    
         ActiveSheet.ChartObjects("MyChart") ' a chart that has been named "MyChart"
    
         ActiveChart.Parent ' the chart object containing the selected chart
    
    'Given that you know your standard sizes, in points (1/72 inch, plus or minus a printer fudge factor of a few 'percent, which is why God invented trial-and-error), you use this kind of approach:
    
         With ActiveChart.Parent
             .Height = 325 ' resize
             .Width = 500  ' resize
             .Top = 100    ' reposition
             .Left = 100   ' reposition
         End With
    
    'Suppose I want to line up a chart to cover a range in the worksheet. I can do this very easily using a range 'object variable and chartobject variable:
    
         Sub CoverRangeWithAChart()
             Dim RngToCover As Range
             Dim ChtOb As ChartObject
             Set RngToCover = ActiveSheet.Range("D5:J19")
             Set ChtOb = ActiveChart.Parent
             ChtOb.Height = RngToCover.Height ' resize
             ChtOb.Width = RngToCover.Width   ' resize
             ChtOb.Top = RngToCover.Top       ' reposition
             ChtOb.Left = RngToCover.Left     ' reposition
         End Sub
    
    'You can carry out this procedure a little further, using some of your best 6th grade algebra, to line up the 'charts on your worksheet:
    
         Sub LineUpMyCharts()
             Dim MyWidth As Single, MyHeight As Single
             Dim NumWide As Long
             Dim iChtIx As Long, iChtCt As Long
    
             MyWidth = 200
             MyHeight = 150
             NumWide = 3
    
             iChtCt = ActiveSheet.ChartObjects.Count
             For iChtIx = 1 To iChtCt
                 With ActiveSheet.ChartObjects(iChtIx)
                     .Width = MyWidth
                     .Height = MyHeight
                     .Left = ((iChtIx - 1) Mod NumWide) * MyWidth
                     .Top = Int((iChtIx - 1) / NumWide) * MyHeight
                 End With
             Next
         End Sub
    Thanks a lot for your help in advance.
    Last edited by romperstomper; 11-02-2010 at 06:06 AM. Reason: mark solved

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