Copy Formula from Sheet2 to Sheet1

Nick70

Active Member
Joined
Aug 20, 2013
Messages
306
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

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
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,224,754
Messages
6,180,749
Members
452,996
Latest member
nelsonsix66

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