Selasa, 27 Maret 2012

[ExcelVBA] Using Literals in Formulas

 

Assume Col A has a list of fruit names, and A1 contains "Apples". I can use the following code
Range("B1").Value = "= ""Ripe "" & A1 & "" Cheap"""
to get "Ripe " & A1 & " Cheap" which displays as Ripe Apples Cheap in B1. The contents of B1 can be copied down Col B giving Ripe Watermelon Cheap, etc. in Col B.

But suppose instead of Ripe I have a long string. I'd like to define a variable, S1 to be that string, and enter something like "= S1 & A1 & ""Cheap""" into B1, but I can't figure out how to do that. When I finally got the quotation marks right to avoid a syntax error, S1, not the literal it represents, was entered and that was flagged as a #Name error.

I realize I could enter that long literal into a cell, and simply reference that cell, but I wonder if there is any way other than that.

Thanks in advance

__._,_.___
Recent Activity:
----------------------------------
Be sure to check out TechTrax Ezine for many, free Excel VBA articles! Go here: http://www.mousetrax.com/techtrax to enter the ezine, then search the ARCHIVES for EXCEL VBA.

----------------------------------
Visit our ExcelVBA group home page for more info and support files:
http://groups.yahoo.com/group/ExcelVBA

----------------------------------
More free tutorials and resources available at:
http://www.mousetrax.com

----------------------------------
.

__,_._,___

Tidak ada komentar:

Posting Komentar