VBA to insert formula into cell

EssKayKay

Active Member
Joined
Jan 5, 2003
Messages
417
Office Version
  1. 2007
Platform
  1. Windows
I’m trying to insert a formula into a cell (or range of cells). The formula is =IF(R33<$T$28,1,"")
Then copy the formula down from T33 to some other cell that changes in that row but as example let’s use cell T100 (i.e., range "T33:T100").

Here’s my VBA code to insert the formula Range("T33").Formula = "=IF(R33<$T$28,1,"")"
but I receive a Run-time error 1004 Application-defined or object-defined error

Thanks for viewing,
Steve K.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
First you need to use two quote marks when you are inside quotes:
Rich (BB code):
"=IF(R33<$T$28,1,"""")"

But the way to do what you want to is
VBA Code:
Range("T33:T100").FormulaR1C1 = "=IF(RC[-2]<R28C20,1,"""")"

Then you don't need to copy it down.
 
Upvote 0
Solution
First you need to use two quote marks when you are inside quotes:
Rich (BB code):
"=IF(R33<$T$28,1,"""")"

But the way to do what you want to is
VBA Code:
Range("T33:T100").FormulaR1C1 = "=IF(RC[-2]<R28C20,1,"""")"

Then you don't need to copy it down.
Excellent -thank you 6string for getting back to me - works perfect.
Again, much appreciated . . .
 
Upvote 0

Forum statistics

Threads
1,224,809
Messages
6,181,076
Members
453,020
Latest member
mattg2448

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