Forum Discussion

JoeCavasin's avatar
JoeCavasin
Brass Contributor
Dec 01, 2021

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

  • JoeCavasin 

    Quotes within a quoted string must be doubled:

     

    Range("F2").Formula = "=IF(COUNTBLANK($B2:$D2)>0,""Recheck Entries, Data Missing"",$E2-$D2)"

    • JoeCavasin's avatar
      JoeCavasin
      Brass Contributor
      Thanks Hans! I knew it would be a simply stupid mistake, always is.
      Cheers!

Resources