Help Please! VbScript and Excel Formula

I have a VbScript that creates an Excel Spreadsheet and writes in formula. I have a formula that I am trying to add a function with it but it does not give me the result I am looking for. The below formula should add the current date whenever approved w/ comments or approved is selected, but at the time of creation it hard codes the date for the creation date instead.  Experts please tell me what I am doing wrong.

Formula:  

objSheet.Cells(5, 2).formula = "=IF(G7=" & Chr(34) & "Approved w/Comments" & Chr(34) & ","  & chr(34) & FormatDateTime(Now(),vbShortDate) & Chr(34) & ",IF(G7=" &chr(34)& "Approved" &chr(34)& "," &chr(34)& FormatDateTime(Now(),vbShortDate) &chr(34)& "," & chr(34) & chr(34) & "))"

Output:
=IF(G7="Approved w/Comments","8/21/2018",IF(G7="Approved","8/21/2018",""))
Eduardo AvilesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewCommented:
This should do what you described, picking up the current date.

objSheet.Cells(5, 2).formula = "=IF(G7=" & Chr(34) & "Approved w/Comments" & Chr(34) & ",TODAY(),IF(G7=" & chr(34) & "Approved" & chr(34)& ",TODAY()," & chr(34) & chr(34) & "))"

Open in new window


»bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Eduardo AvilesAuthor Commented:
Thank you Bill Prew, it is exactly what I needed.  Thank you
0
Bill PrewCommented:
Welcome.


»bp
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.