+ Reply to Thread
Results 1 to 6 of 6

Variable in string

Hybrid View

  1. #1
    Registered User
    Join Date
    04-27-2005
    Posts
    2

    Variable in string

    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

  2. #2
    Norman Jones
    Guest

    Re: Variable in string

    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 & "."



    ---
    Regards,
    Norman


    "DevinC" <DevinC.227wam_1138237801.391@excelforum-nospam.com> wrote in
    message news:DevinC.227wam_1138237801.391@excelforum-nospam.com...
    >
    > 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
    >
    >
    > --
    > DevinC
    > ------------------------------------------------------------------------
    > DevinC's Profile:
    > http://www.excelforum.com/member.php...o&userid=22739
    > View this thread: http://www.excelforum.com/showthread...hreadid=505186
    >




  3. #3
    Norman Jones
    Guest

    Re: Variable in string

    Hi Devin,

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


    should read:

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

    ---
    Regards,
    Norman



  4. #4
    Broadband Al
    Guest

    RE: Variable in string

    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

    "DevinC" wrote:

    >
    > 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
    >
    >
    > --
    > DevinC
    > ------------------------------------------------------------------------
    > DevinC's Profile: http://www.excelforum.com/member.php...o&userid=22739
    > View this thread: http://www.excelforum.com/showthread...hreadid=505186
    >
    >


  5. #5
    Ken Johnson
    Guest

    Re: Variable in string

    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


  6. #6
    Registered User
    Join Date
    04-27-2005
    Posts
    2

    Smile

    Thanks guys!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1