Would it be possible to optimize the code below?
Thanks!
Code:
Sub Graphs()Dim lr As Integer, lc As Integer, r As Integer
Sheets("data_pivot").Visible = True
lr = data.Cells(Rows.Count, 1).End(xlUp).Row
lc = data.Cells(1, Columns.Count).End(xlToLeft).Column
lr2 = data_pivot.Cells(Rows.Count, 1).End(xlUp).Row
lc2 = data_pivot.Cells(1, Columns.Count).End(xlToRight).Column
data_pivot.Range(data_pivot.Cells(1, 1), data_pivot.Cells(lr, lc)).Clear
For r = 1 To lr
data.Rows(r).Copy
data_pivot.Select
data_pivot.Cells(r, 1).Select
data_pivot.Paste
Next
MsgBox "Copy done"
Range("data2[#All]").Select
Sheets("Graph1").Visible = True
Sheets("Graph2").Visible = True
Graph1.Select
ActiveSheet.PivotTables("PivotTable18").PivotCache.Refresh
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ChartArea.Copy
Sheets("Dashboard_Graphs").Select
ActiveSheet.Paste
ActiveSheet.Shapes("graph1").Height = 541.4173228346
ActiveSheet.Shapes("graph1").Width = 653.3858267717
ActiveSheet.Shapes("graph1").Left = Range("F7").Left
ActiveSheet.Shapes("graph1").Top = Range("G8").Top
Graph2.Select
ActiveSheet.PivotTables("PivotTable19").PivotCache.Refresh
ActiveSheet.ChartObjects("graph2").Activate
ActiveChart.ChartArea.Copy
Sheets("Dashboard_Graphs").Select
ActiveSheet.Paste
ActiveSheet.Shapes("graph2").Height = 433.9842519685
ActiveSheet.Shapes("graph2").Width = 723.968503937
ActiveSheet.Shapes("graph2").Left = Range("U7").Left
ActiveSheet.Shapes("graph2").Top = Range("G5").Top
Sheets("Graph2").Visible = False
Sheets("Graph1").Visible = False
Sheets("data_pivot").Visible = False
Dashboard_Graphs.Select
End Sub
Thanks!
Last edited: