How to copy and formula paste multiple tabs using a macro

jeffroth94

New Member
Joined
Dec 29, 2015
Messages
8
Currently I use a macro to create a workbook with everyday of the month as the title of every tab. I am able to copy the template, that I have created, for each spreadsheet but it can get annoying to have to go in and copy and formula paste every time. Here is my current formula:

‘Code Starts here

Sub Dtpopulate()
Dim S As Integer
Dim X As Integer
S = Sheets("Temp").Range("c5").Value
For X = 1 To S
newname = Sheets("Temp").Range("a6").Value
Worksheets("Template").Activate
Sheets("Template").Cells.Select
Selection.Copy


Sheets.Add.Name = newname
Sheets(newname).Cells.Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False

Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

Sheets("Temp").Range("d5").Value = Sheets("Temp").Range("b5") + X
Next X

End Sub

Can I add more to this formula to be able to copy and paste formula?
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Can I add more to this formula to be able to copy and paste formula?

What exactly do you want to copy and paste? What cells, from where and to where? It looks like your code is already pasting values and formats...

This should do the same exact thing your code does, except it will copy everything rather than just the values/formats:

Code:
Sub Dtpopulate()
Dim S As Integer, X As Integer


S = Sheets("Temp").Range("C5").Value


For X = 1 To S
    newname = Sheets("Temp").Range("A6").Value
    Worksheets("Template").Sheets("Template").Cells.Copy _
        Sheets(newname).Range("A1")
        
    Sheets.Add.Name = newname
    Sheets("Temp").Range("D5").Value = Sheets("Temp").Range("B5") + X
Next X


End Sub
 
Last edited:
Upvote 0
I want to copy and paste the formulas from the template. Right, it does copy and paste the values and the format but it does not copy the formulas in cells C9:K57. Svendiamond, your formula is giving me an error that the subscript is out of range. Do I need to add to the formula?
 
Upvote 0
When you click "Debug" what line is highlighted in yellow? Actually I think I see the problem. Try this:

Code:
Sub Dtpopulate()Dim S As Integer, X As Integer


S = Sheets("Temp").Range("C5").Value


For X = 1 To S
    newname = Sheets("Temp").Range("A6").Value
    Sheets.Add.Name = newname
    Worksheets("Template").Sheets("Template").Cells.Copy _
        Sheets(newname).Range("A1")


    Sheets("Temp").Range("D5").Value = Sheets("Temp").Range("B5") + X
Next X


End Sub
 
Upvote 0

Forum statistics

Threads
1,216,058
Messages
6,128,538
Members
449,456
Latest member
SammMcCandless

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