Forum Discussion
Excel VBA - adding formula to specific cell
Morning All. I'm encountering errors for "expected end of statement" when i try to use VBA to add a specific formula to a specific cell. Can anyone advise the appropriate syntax? I haven't been able to find a way to fix this and this is needed to help error check >20 users input in their downtime tracking sheets.
Current formula setting works as below:
' Reset Time Gap Formula
Range("F2").Formula = "=$E2-$D2"
Goal - i want to change the "=$E2-$D2" to =IF(COUNTBLANK($B2:$D2)>0,"Recheck Entries, Data Missing",$E2-$D2).
Any version of the error checking formula is unfortunately throwing errors in VBA. Any syntax help would be greatly appreciated!
2 Replies
Quotes within a quoted string must be doubled:
Range("F2").Formula = "=IF(COUNTBLANK($B2:$D2)>0,""Recheck Entries, Data Missing"",$E2-$D2)"
- JoeCavasinBrass ContributorThanks Hans! I knew it would be a simply stupid mistake, always is.
Cheers!