Format All Graphs

Pestomania

Active Member
Joined
May 30, 2018
Messages
332
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

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
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,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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