Modifying a VBA code

jondavis1987

Active Member
Joined
Dec 31, 2015
Messages
443
Office Version
  1. 2019
Platform
  1. Windows
So i recorded a macro for what I am trying to do. I have a worksheet called Superpave Template. I regularly have to create add a new sheet to the book and copy everything from the superpave template into the new sheet. The problem is the chart doesn't update automatically to the new sheet. It still pulls from the Superpave Template. That's what all of this is trying to do. keep getting an error on the line that i put asterisks on. The error code says object with specified name can't be found

VBA Code:
Option Explicit

Sub New_Superpave()
'
' New_Superpave Macro
'

'
    Sheets.Add After:=ActiveSheet
    Sheets("Superpave Template").Select
    Cells.Select
    Selection.Copy
    Sheets("Sheet3").Select
    ActiveSheet.Buttons.Add(891.75, 63, 91.5, 30).Select
    ActiveSheet.Paste
   * ActiveSheet.ChartObjects("Chart 1").Activate *
    ActiveChart.PlotArea.Select
    Application.CutCopyMode = False
    Application.CutCopyMode = False
    Application.CutCopyMode = False
    Application.CutCopyMode = False
    Application.CutCopyMode = False
    Application.CutCopyMode = False
    ActiveChart.FullSeriesCollection(1).Values = "=Sheet3!$L$9:$L$19"
    ActiveChart.FullSeriesCollection(2).Values = "=Sheet3!$M$9:$M$19"
    ActiveChart.FullSeriesCollection(3).Values = "=Sheet3!$O$9:$O$19"
    ActiveChart.FullSeriesCollection(4).Values = "=Sheet3!$P$9:$P$19"
End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
hi, mickerckson nice code but if there are way if change data in activesheet and copy to after activesheet not every time update data add a new sheet it adds many sheets maybe 50 sheets if i have changes data so i supposing updating is the same sheet is ok
 
Upvote 0
I'm not sure if I understand what you want.
But if you have a template sheet and you want to copy that sheet and then change some of data on the new sheet, you could then copy, not the original template sheet, but the new one 50 times.
Or are there 50 different variations you want to make all based on data from the ActiveSheet? If so something like

VBA Code:
Dim homeSheet as worksheet

Set homeSheet = ActiveSheet

For i = 1 to 50
    Sheets("Template").Copy after:=HomeSheet 
    ActiveSheet.Range("A1") = homeSheet.Cells(i,2)
Next i
 
Upvote 0
sorry mickerckson if i don't make clear enough you misunderstood me i don't want create 50 sheets when create a new sheet after main sheet it doesn't suppose creating a new sheets every time change data in main sheet just updating data which is created new sheet
 
Upvote 0

Forum statistics

Threads
1,213,538
Messages
6,114,217
Members
448,554
Latest member
Gleisner2

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