Paste formula to cells on a command button RTE 1004

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,279
Office Version
  1. 2007
Platform
  1. Windows
I am having an issue when i am pasting formulas to worksheet cells.

This is what i have in use but im getting RTE 1004 Application defined or object defined error
Can you advise please

Rich (BB code):
Private Sub PasteFormulas_Click()
     Dim WS As Worksheet

     Set WS = Worksheets("INV")

     WS.Range("G14").Formula = "=IFERROR(IF(INDEX(DATABASE!R:R,$H$13)=0,"",INDEX(DATABASE!R:R,$H$13)),"")"
     WS.Range("G15").Formula = "=IFERROR(IF(INDEX(DATABASE!S:S,$H$13)=0,"",INDEX(DATABASE!S:S,$H$13)),"")"
     WS.Range("G16").Formula = "=IFERROR(IF(INDEX(DATABASE!T:T,$H$13)=0,"",INDEX(DATABASE!T:T,$H$13)),"")"
     WS.Range("G17").Formula = "=IFERROR(IF(INDEX(DATABASE!U:U,$H$13)=0,"",INDEX(DATABASE!U:U,$H$13)),"")"
     WS.Range("G18").Formula = "=IFERROR(IF(INDEX(DATABASE!V:V,$H$13)=0,"",INDEX(DATABASE!V:V,$H$13)),"")"
     
     WS.Range("L14").Formula = "=IFERROR(IF(INDEX(DATABASE!D:D,$H$13)=0,"",INDEX(DATABASE!D:D,$H$13)),"")"
     WS.Range("L15").Formula = "=IFERROR(IF(INDEX(DATABASE!B:B,$H$13)=0,"",INDEX(DATABASE!B:B,$H$13)),"")"
     WS.Range("L16").Formula = "=IFERROR(IF(INDEX(DATABASE!L:L,$H$13)=0,"",INDEX(DATABASE!L:L,$H$13)),"")"
     WS.Range("L17").Formula = "=IFERROR(IF(INDEX(DATABASE!W:W,$H$13)=0,"",INDEX(DATABASE!W:W,$H$13)),"")"
         
     
End Sub
 

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.
You'll need to double up on the quotes within the string contained in quotes...

Excel Formula:
WS.Range("G14").Formula = "=IFERROR(IF(INDEX(DATABASE!R:R,$H$13)=0,"""",INDEX(DATABASE!R:R,$H$13)),"""")"

And the same thing applies to your other formulas.

Hope this helps!
 
Upvote 0
Sorted,many thanks.
I knew it wasnt something massive.

Now to continue with the problem i have.
 
Upvote 0
Can i quickly ask a question following on from above.

If i add the following i then see FALSE in the cell.
Did i write it correctly ?

Rich (BB code):
WS.Range("M27").Formula = "=IF(AND(H27="",H27=""),"",H27*J27),"")"
 
Upvote 0
Don't forget that quotes within a string need to be doubled up. So I think you want...

VBA Code:
WS.Range("M27").Formula = "=IF(AND(H27="""",H27=""""),"""",H27*J27)"

Hope this helps!
 
Upvote 0
Solution

Forum statistics

Threads
1,216,222
Messages
6,129,586
Members
449,520
Latest member
TBFrieds

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