Reputation: 179
I am trying to run a macro that will automatically insert the formula
=IFERROR(IF('307'!A2=0,"-",'307'!A2),"-")
When I have the VBA code setup with the code below it does not work. I just get the type mismatch error.
Range("B2:B33").Formula = "=IFERROR(IF('307'!A2=0," - ",'307'!A2)," - ")"
Essentially what I want to have happen is the formula to be inserted and then the next formula would have 'A3' the next 'A4' and so on. Is there a simple way of achieving this?
Thanks in advance.
Upvotes: 0
Views: 61
Reputation:
As Scott Craner pointed out: In order to escape quotes "you need to double them".
Here is an easy trick to double all of your quotes.
?Replace(Range("A1").Formula,Chr(34),Chr(34)& Chr(34))
=IFERROR(IF('307'!A2=0,""-"",'307'!A2),""-"")
Upvotes: 0
Reputation: 152505
If you want the quotes to show then you need to double them in vba:
"=IFERROR(IF('307'!A2=0,"" - "",'307'!A2),"" - "")"
Upvotes: 2