Copy formula from a one sheet to another when running a macro

lewis94

New Member
Joined
Nov 2, 2008
Messages
14
I have a macro that pulls a column from one worksheet to another, formats it etc but it is not copying over the formula

For example, on the column I am copying it has a cell with the content of +Y4/Y2, and I need this to also transfer over but with the sheet name to refer it back to the original sheet.

Regards
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Perhaps you are after something a tad more complex, but the simplest method would be to use absolute references and sheet names in the original formula.
=+(Sheet1!$W$4/Sheet1!$W$2)

Then you can simply paste special formulas as below.

Code:
Sub CopyFormula()
    Selection.Copy
    Sheets("Sheet2").Select
    Range("A1").Select
    Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
End Sub
 
Upvote 0
Thank you for your reply.

I pull the sheet name from an inout box using "Trim(arr(0)"

I have used the following but if I add in the formula element it crashes and requires debug

Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
 
Upvote 0
My understading of PasteSpecial is that it can perform only one core function at a time (formula or formats) try the below:

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

Forum statistics

Threads
1,224,820
Messages
6,181,154
Members
453,021
Latest member
Justyna P

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