Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub MakeGridOfCharts()
- Const nRowsTall As Long = 20
- Const nColsWide As Long = 10
- ' chart layout - adjust as desired
- Const nChartsPerRow As Long = 3
- Const nSkipRows As Long = 2
- Const nSkipCols As Long = 1
- Const nFirstRow As Long = 3
- Const nFirstCol As Long = 2
- Dim iChart As Long
- Dim chtob As ChartObject
- Dim dWidth As Double
- Dim dHeight As Double
- Dim rData As Range
- Dim dFirstChartTop As Double
- Dim dFirstChartLeft As Double
- Dim dRowsBetweenChart As Double
- Dim dColsBetweenChart As Double
- If ActiveSheet.ChartObjects.Count > 0 Then
- With ActiveSheet.Cells(nFirstRow, nFirstCol)
- If nRowsTall * nColsWide > 0 Then
- dWidth = nColsWide * .Width
- dHeight = nRowsTall * .Height
- Else
- If Not ActiveChart Is Nothing Then
- Set chtob = ActiveChart.Parent
- Else
- Set chtob = ActiveSheet.ChartObjects(1)
- End If
- dWidth = chtob.Width
- dHeight = chtob.Height
- End If
- dFirstChartLeft = .left
- dFirstChartTop = .top
- dRowsBetweenChart = nSkipRows * .Height
- dColsBetweenChart = nSkipCols * .Width
- End With
- For iChart = 1 To ActiveSheet.ChartObjects.Count
- Set chtob = ActiveSheet.ChartObjects(iChart)
- With chtob
- .left = ((iChart - 1) Mod nChartsPerRow) * _
- (dWidth + dColsBetweenChart) + dFirstChartLeft
- .top = Int((iChart - 1) / nChartsPerRow) * _
- (dHeight + dRowsBetweenChart) + dFirstChartTop
- .Width = dWidth
- .Height = dHeight
- End With
- With chtob.Chart.Axes(xlCategory)
- .HasTitle = True
- .AxisTitle.Characters.Text = "Likelihood"
- .MinimumScale = 0
- .MaximumScale = 15
- End With
- With chtob.Chart.Axes(xlValue)
- .HasTitle = True
- .AxisTitle.Characters.Text = "Impact"
- .MinimumScale = 0
- .MaximumScale = 15
- End With
- chtob.Chart.ChartStyle = 43
- With chtob.Chart.PlotArea.Format.Fill
- .OneColorGradient msoGradientHorizontal, 1, 1
- .BackColor.RGB = RGB(255, 0, 0)
- .GradientStops.Insert RGB(0, 220, 0), 0
- .GradientStops.Insert RGB(255, 180, 0), 0.4
- .GradientStops.Insert RGB(255, 180, 0), 0.6
- .GradientStops.Insert RGB(255, 0, 0), 0.85
- .GradientAngle = 310
- End With
- Next
- End If
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement