Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. Sub MakeGridOfCharts()
  2.  
  3. Const nRowsTall As Long = 20
  4. Const nColsWide As Long = 10
  5.  
  6. ' chart layout - adjust as desired
  7. Const nChartsPerRow As Long = 3
  8. Const nSkipRows As Long = 2
  9. Const nSkipCols As Long = 1
  10. Const nFirstRow As Long = 3
  11. Const nFirstCol As Long = 2
  12.  
  13. Dim iChart As Long
  14. Dim chtob As ChartObject
  15. Dim dWidth As Double
  16. Dim dHeight As Double
  17. Dim rData As Range
  18. Dim dFirstChartTop As Double
  19. Dim dFirstChartLeft As Double
  20. Dim dRowsBetweenChart As Double
  21. Dim dColsBetweenChart As Double
  22.  
  23. If ActiveSheet.ChartObjects.Count > 0 Then
  24.  
  25. With ActiveSheet.Cells(nFirstRow, nFirstCol)
  26. If nRowsTall * nColsWide > 0 Then
  27. dWidth = nColsWide * .Width
  28. dHeight = nRowsTall * .Height
  29. Else
  30. If Not ActiveChart Is Nothing Then
  31. Set chtob = ActiveChart.Parent
  32. Else
  33. Set chtob = ActiveSheet.ChartObjects(1)
  34. End If
  35. dWidth = chtob.Width
  36. dHeight = chtob.Height
  37. End If
  38.  
  39. dFirstChartLeft = .left
  40. dFirstChartTop = .top
  41. dRowsBetweenChart = nSkipRows * .Height
  42. dColsBetweenChart = nSkipCols * .Width
  43. End With
  44.  
  45. For iChart = 1 To ActiveSheet.ChartObjects.Count
  46. Set chtob = ActiveSheet.ChartObjects(iChart)
  47. With chtob
  48. .left = ((iChart - 1) Mod nChartsPerRow) * _
  49. (dWidth + dColsBetweenChart) + dFirstChartLeft
  50. .top = Int((iChart - 1) / nChartsPerRow) * _
  51. (dHeight + dRowsBetweenChart) + dFirstChartTop
  52. .Width = dWidth
  53. .Height = dHeight
  54. End With
  55.  
  56. With chtob.Chart.Axes(xlCategory)
  57. .HasTitle = True
  58. .AxisTitle.Characters.Text = "Likelihood"
  59. .MinimumScale = 0
  60. .MaximumScale = 15
  61. End With
  62. With chtob.Chart.Axes(xlValue)
  63. .HasTitle = True
  64. .AxisTitle.Characters.Text = "Impact"
  65. .MinimumScale = 0
  66. .MaximumScale = 15
  67. End With
  68. chtob.Chart.ChartStyle = 43
  69. With chtob.Chart.PlotArea.Format.Fill
  70. .OneColorGradient msoGradientHorizontal, 1, 1
  71. .BackColor.RGB = RGB(255, 0, 0)
  72. .GradientStops.Insert RGB(0, 220, 0), 0
  73. .GradientStops.Insert RGB(255, 180, 0), 0.4
  74. .GradientStops.Insert RGB(255, 180, 0), 0.6
  75. .GradientStops.Insert RGB(255, 0, 0), 0.85
  76. .GradientAngle = 310
  77. End With
  78.  
  79.  
  80.  
  81.  
  82. Next
  83.  
  84. End If
  85.  
  86. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement