Copying formulas between workbooks

RichardMGreen

Well-known Member
Joined
Feb 20, 2006
Messages
2,177
Hi all

I need to copy a load of formulas between workbook without copying the sheets themselves.
All the formulas will be in the same cells (A1 to A1) and the sheet names are identical.
I've got this piece of code :-
Code:
Sub copier()
    Dim wb1 As Workbook, wb2 As Workbook, ws1 As Worksheet, ws2 As Worksheet, rng As Range
    Set wb1 = Workbooks("NOCREP0036 - TEMPLATE 111 Report Dashboard updating version v1.33.xls")
    Set wb2 = ThisWorkbook
    For Each ws In wb1.Worksheets
        sheet_name = ws.Name
        wb1.Sheets(sheet_name).Select
        For Each rng In ActiveSheet.UsedRange
            wb2.Sheets(sheet_name).rng.Formula = ActiveSheet.rng.Formula
        Next
    Next
End Sub

but it's falling over on this line :-
wb2.Sheets(sheet_name).rng.Formula = ActiveSheet.rng.Formula

Obviously I'm doing something wrong but I can't see it.

Can anyone point me in the right direction?
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
untested, but maybe
Code:
Sub copier()

    Dim wb1 As Workbook, wb2 As Workbook, ws1 As Worksheet, ws2 As Worksheet, rng As Range
    Set wb1 = Workbooks("NOCREP0036 - TEMPLATE 111 Report Dashboard updating version v1.33.xls")
    Set wb2 = ThisWorkbook
    For Each ws In wb1.Worksheets
        sheet_name = ws.Name
        wb1.Sheets(sheet_name).copy
        wb2.Sheets(sheet_name).PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
        Next
    Next
End Sub</pre>
 
Upvote 0

Forum statistics

Threads
1,224,550
Messages
6,179,462
Members
452,915
Latest member
hannnahheileen

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