简体   繁体   中英

Macros in Excel

This might be a multi-part question based off of the responses, but as of now I am trying to learn how to program with Macros in excel. I know how to use a macro to set any given cell equal to a hard coded value (Like Cells(2,3).Value = 3) and I know how to put a general equation into a cell

(Cells(2,3).FORMULA = "=istext(8,8)"). But when I try to add put an if statement into a cell using excel the machine flips out since it can't handle the double quote.

What I have is Cells(2,3).Formula = "=if (X2 = 1, "You got it", "Missed again")"

What do I need to do in order to get the macro to be happy?

Thanks

(Note in this example things might be a little off since I am not copying and pasting from my work computer. For example maybe on one of my above equations I am missing a comma or something, people have reviewed my work and that is semantics is not a problem)

Inside a string, you want to turn a double quote into a double double quote, for example:

Cells(2,3).Formula = "=if(x2 = 1, ""You got it"", ""Missed again"")"

Note also that you don't want a space after the if and before the bracket. Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM