Optimize code

ORoxo

Board Regular
Joined
Oct 30, 2016
Messages
147
Would it be possible to optimize the code below?

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:

Some videos you may like

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Watch MrExcel Video

Forum statistics

Threads
1,098,857
Messages
5,465,099
Members
406,412
Latest member
superjoejoe

This Week's Hot Topics

Top