Avatar of Eduardo Aviles
Eduardo Aviles
Flag for United States of America asked on

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",""))
VB Script

Avatar of undefined
Last Comment
Bill Prew

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Bill Prew

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Eduardo Aviles

ASKER
Thank you Bill Prew, it is exactly what I needed.  Thank you
Bill Prew

Welcome.


»bp
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23