Reputation: 9393
I want to insert these formula using vba but it throws me an error application defined error
activesheet.range("A4").formula = "=IF(AND($B4>TODAY() -7,$B4 < TODAY()),"ONE WEEK OLD",IF(AND($B4 < TODAY() -7,$B4 > TODAY() - 30),"ONE WEEK TO ONE MONTH OLD",IF(AND($B4 < TODAY()-30,$B4 > TODAY()-90),"1 MONTH TO 90 DAYS OLD","OLDER THAN 90 DAYS")))"
I have used concatenation and also using a string variables but still Im unable to do it.
I am unable to insert a formula in a cell if formula has double quotes in it from vba
Please help me with these Thanks
Upvotes: 1
Views: 5023
Reputation: 41589
You need to escape the quotes in the string. To do this just double them up:
activesheet.range("A4").formula = "=IF(AND($B4>TODAY() -7,$B4 < TODAY()),""ONE WEEK OLD"",IF(AND($B4 < TODAY() -7,$B4 > TODAY() - 30),""ONE WEEK TO ONE MONTH OLD"",IF(AND($B4 < TODAY()-30,$B4 > TODAY()-90),""1 MONTH TO 90 DAYS OLD"",""OLDER THAN 90 DAYS"")))"
If this doesn't help you'll need to post more of the code.
Upvotes: 3