Copy Formula from Sheet2 to Sheet1

Nick70

Active Member
Joined
Aug 20, 2013
Messages
299
Office Version
  1. 365
Platform
  1. Windows
Hi,

I would like to copy a formula from Sheet2 to Sheet1 so that the references do not change.

For example I have formula
Excel Formula:
=IF(AND(E$3>=$C5,E$3<=$C5),$D5,"")
in cell E5 of Sheet2.

If I copy this formula to cell G8 of Sheet1 using code
VBA Code:
Worksheets("Sheet2").Activate
    Range("E5").Select
    Selection.copy
    Sheets("Sheet1").Select
    Range("G8").Select
    Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False
End Sub

the corresponding formula that I will get in cell G8 of Sheet1 will be
Excel Formula:
=IF(AND(G$3>=$C8,G$3<=$C8),$D8,"")
.

I would like to amend the code so that formula that is copied in cell G8 of Sheet1 remains
Excel Formula:
=IF(AND(E$3>=$C5,E$3<=$C5),$D5,"")
so does not change references.

How would I do that?

Thanks,
Nic :unsure:
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Try:

VBA Code:
Sub copy_formula()
  Sheets("Sheet1").Range("G8").Formula = Sheets("Sheet2").Range("E5").Formula
End Sub


But your formula is redundant. A value cannot be less than value X and also be greater than value X.

So the formula should be like this:
Excel Formula:
=IF(E$3=$C5,$D5,"")


----- --
Let me know the result and I'll get back to you as soon as I can.
Sincerely
Dante Amor
----- --
 
Upvote 0
Solution

Forum statistics

Threads
1,215,069
Messages
6,122,959
Members
449,096
Latest member
Anshu121

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