Variable in string

D

DevinC

Hello, is it possible to create a variable within a string of text in a
cell ?

For example,

Variable = YEAR
YEAR = 2006
Data in cell = "Now, we're in YEAR."

will then make Excel recognize the text, YEAR, as a variable and will
appropriately insert the value there, as :

"Now, we're in 2006."

Is this possible to do in Excel?

Thanks,

Devin
 
N

Norman Jones

Hi Devin,

In Excel:

A1: 2006
B1 ="Now, we're in " & A1 & "."

In VBA:

Dim sYear As String

sYear = 2006

Range("A1").Value = "Now, we're in " & Year & "."
 
B

Broadband Al

Sounds like you need the CONCATENATE function. Cell formula should be:
=concatenate("Now we're in "&YEAR)
This assumes you have named a cell "YEAR". If not, replace YEAR with your
cell ref.

Al
 
K

Ken Johnson

Hi Devin,
without using a variable the following in any cell will update for
whatever year it happens to be:

="Now, we're in " & YEAR(NOW()) & "."

Ken Johnson
 
Top