View Full Version : Expressing a " in an excel Formula as VBA code
Nick2612
07-19-2011, 07:51 AM
Hi, I'm really in need of some help with the following. I have an excel formula I want to translate into VBA code. The formula contains quotation marks so is returning an error when testing. How do I get VBA to read the quotation marks as quotation marks and not as the start/end of a line?
Thanks
Aflatoon
07-19-2011, 08:03 AM
You need to double them up in the quoted string. For example:
=IF(A1="","",A1)
would become:
Activecell.Formula = "=IF(A1="""","""",A1)"
Paul_Hossler
07-19-2011, 08:44 AM
If the fomula is complicated and/or contains single quotes (') I find it can get hard to read all the "'s
Q = Chr(34)
Activecell.Formula = "=IF(A1=" & Q & "," & Q & ",A1)"
or just
Activecell.Formula = "=IF(A1=" & Chr(34) & "," & Chr(34) & ",A1)"
Paul
Aflatoon
07-19-2011, 08:47 AM
Each to their own, I suppose. I find all that concatenation far harder to read. :)
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.