Format All Graphs

Pestomania

Active Member
Joined
May 30, 2018
Messages
292
Office Version
  1. 365
Platform
  1. Windows
Hi there!!

I have 30+ graphs on a "dashboard" that keep getting formatted wrong whenever a row is added or deleted.

Is there a way to make all graphs the same size (2.95" x 4.48") and put a 0.025" space in the vertical with a 0.005" space in the horizontal between each graph.
1702922929563.png
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Try this macro. You just have to edit the code where indicated to specify the name of the 'Dashboard' sheet and the cell where the first chart should be positioned.

VBA Code:
Public Sub Position_Charts()

    Dim DashboardSheet As Worksheet
    Dim c As Long
    Dim chart1Left As Double
    Dim chartTop As Double, chartLeft As Double, chartWidth As Double, chartHeight As Double
    Dim verticalGap As Double, horizontalGap As Double
    
    chartWidth = Application.InchesToPoints(4.48)
    chartHeight = Application.InchesToPoints(2.95)
    verticalGap = Application.InchesToPoints(0.025)
    horizontalGap = Application.InchesToPoints(0.005)
    
    'Define Dashboard sheet
    Set DashboardSheet = ThisWorkbook.Worksheets("Charts")  'SPECIFY SHEET NAME
    
    'Define position of first chart
    With DashboardSheet.Range("D4")                         'SPECIFY CELL
        chartTop = .Top
        chartLeft = .Left
    End With
    
    chart1Left = chartLeft
    
    With DashboardSheet
        For c = 1 To .ChartObjects.Count
            .ChartObjects(c).Top = chartTop
            .ChartObjects(c).Left = chartLeft
            .ChartObjects(c).Width = chartWidth
            .ChartObjects(c).Height = chartHeight
            If c Mod 2 = 0 Then
                '2 charts per row - next row
                chartTop = chartTop + chartHeight + horizontalGap
                chartLeft = chart1Left
            Else
                chartLeft = chartLeft + chartWidth + verticalGap
            End If
        Next
    End With
    
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,139
Messages
6,123,262
Members
449,093
Latest member
Vincent Khandagale

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top