ORoxo

Board Regular
Joined
Oct 30, 2016
Messages
149
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:

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Forum statistics

Threads
1,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

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