+ Reply to Thread
Results 1 to 6 of 6

Concatenating a "variable.formula" and "variable.value" in a Cell

  1. #1
    Registered User
    Join Date
    10-25-2016
    Location
    mumbai
    MS-Off Ver
    2010
    Posts
    47

    Concatenating a "variable.formula" and "variable.value" in a Cell

    Hello Guys,
    I would like to know if there is a way to concatenate a variable.formula and variable.value.
    I have written the following lines of code:

    sub xyz()
    dim x as string
    dim y as string
    x=Range("A1").Formula
    y = Range("A2").Value
    Range("A3").Value = x & y
    End Sub

    Range A1 contains a formula and its value can change according to some other cells. When I am printing the value in A3, its showing the value of "x" as just the formula instead of it curent value when concatenated with the value in A2.
    Kindly help me. Thanks in Advance

  2. #2
    Registered User
    Join Date
    11-01-2012
    Location
    Cairo, Egypt
    MS-Off Ver
    MS Office 2013
    Posts
    76

    Re: Concatenating a "variable.formula" and "variable.value" in a Cell

    You have a formula in Range("A1"), and you world like to concatenate (the formula with the value) and assign the result to Range("A3")
    Just like if You have e.g: Formula Now(), So Range("A3").Value would be: "Now(), 23/11/2016 01:27:26 P.M"
    Is that Right?!!!

  3. #3
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    Concatenating a "variable.formula" and "variable.value" in a Cell. Range Object Properties

    Hi AdiK
    Quote Originally Posted by AdiK View Post
    Hello Guys,
    _1 I would like to know if there is a way to concatenate a variable.formula and variable.value.
    _2 Range A1 contains a formula and its value can change according to some other cells. When I am printing the value in A3, its showing the value of "x" as just the formula instead of it curent value when concatenated with the value in A2.
    You seem to be asking two different questions
    Subverter has given you the answer to question _1

    This is the answer to question_2
    Please Login or Register  to view this content.
    .Value and .Formula are two Properties for a Range Object

    .Value will be the "value" you typically "see"
    .Formula will be a string of the formula for the cell ( if it has one ) in the "column letter and row number" type convention notation
    http://www.excelforum.com/showthread...=8#post4519378


    Alan

    P.s.
    See here for example – you can see some of the Properties of the Range Object:
    To get for example this for your cell A1,
    _goto the VB Editor,
    _1 ) Put a stop at End Sub by clicking in the margin to the left of End Sub until a round brown symbol appears in the margin to the left of End Sub
    _2) Run your code – it should stop at End Sub
    _ 3) Highlight Range("A1") in your code
    _ 4) Hit Shift+F9 to display the Watch window
    _ 5) click on the + in Watch Window to reveal Range Object Properties http://imgur.com/l8zJfmU
    WatchWindowA1.JPG
    http://imgur.com/Ms0nbN7
    ImmediateAndWatchWindow.JPG
    http://imgur.com/a/auaRM


    WatchWindowA1.JPG



    http://www.excelforum.com/showthread...=8#post4519378
    Last edited by Doc.AElstein; 11-24-2016 at 06:59 AM.
    '_- Google first, like this _ site:ExcelForum.com Gamut
    Use Code Tags: Highlight code; click on the # icon above,
    Post screenshots COPYABLE to a Spredsheet; NOT IMAGES PLEASE
    http://www.excelforum.com/the-water-...ml#post4109080
    https://app.box.com/s/gjpa8mk8ko4vkwcke3ig2w8z2wkfvrtv
    http://excelmatters.com/excel-forums/ ( Scrolll down to bottom )

  4. #4
    Valued Forum Contributor kasan's Avatar
    Join Date
    07-22-2009
    Location
    Riga, Latvia
    MS-Off Ver
    Excel 2010
    Posts
    680

    Re: Concatenating a "variable.formula" and "variable.value" in a Cell

    Try this one
    Please Login or Register  to view this content.
    Doc.AElstein, I assumed that Subverter in his post clarified/described the question better than Topic Starter. Actually I don`t see multiply questions in this post.
    Issue is to get formula from the cell as text + value of this formula.
    So my proposal is to convert formula and value of the formula - to strings (with CStr function) and this symbol before the result "'" - just to be sure that x+y will be represented in cell as text, because if x+y is "=if(...)TRUE" than after inserting this text into a cell - excel might understand the first string symbol (=) as a start of formula and error will accure.
    Last edited by kasan; 11-24-2016 at 09:38 AM.

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this !

    PHP Code: 
    Sub Demo()
        [
    A3].Value Mid([A1].Formula2) & " = " & [A1].Value
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  6. #6
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    Re: Concatenating a "variable.formula" and "variable.value" in a Cell

    Quote Originally Posted by kasan View Post
    ....

    Doc.AElstein, I assumed that Subverter in his post clarified/described the question better than Topic Starter. Actually I don`t see multiply questions in this post.
    Issue is to get formula from the cell as text + value of this formula.
    So my proposal is to convert formula and value of the formula - to strings (with CStr function) and this symbol before the result "'" - just to be sure that x+y will be represented in cell as text, because if x+y is "=if(...)TRUE" than after inserting this text into a cell - excel might understand the first string symbol (=) as a start of formula and error will accure.
    Hi kasan.
    Thanks for the clarification.

    I saw two questions as the OP had written.
    _2 )
    Quote Originally Posted by AdiK View Post
    .....
    Range A1 contains a formula and its value can change according to some other cells. When I am printing the value in A3, its showing the value of "x" ( x= A1) as just the formula instead of it curent value when concatenated with the value in A2.(A2 is y - probably a value ..)


    _1)
    Quote Originally Posted by AdiK View Post
    I would like to know if there is a way to concatenate a variable.formula and variable.value. ....
    - I though this might mean the same variable
    But I suspet someone has given him what he wanted - you and I gave him
    2 ) I think -
    ( Your "'" was a good idea )
    Marc L gave him 1 )

    In any case I The OP should have a plenty of good info. to get what is wanted

    Alan
    Last edited by Doc.AElstein; 11-24-2016 at 01:11 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 4
    Last Post: 11-17-2013, 12:05 PM
  2. [SOLVED] How to USE """"" cells count """"" change font color
    By austin123456 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-09-2013, 06:14 AM
  3. Replies: 4
    Last Post: 07-12-2013, 12:14 PM
  4. [SOLVED] Variable "sheet-name" and "range-name" wanted in INDEX/MATCH-function
    By Fiebuls in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-01-2012, 04:09 PM
  5. Replies: 5
    Last Post: 10-12-2010, 06:46 AM
  6. Error msgs: "Object varible or with block variable not set"; "subscript out of range"
    By menyanthe in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-26-2009, 04:58 PM
  7. If changed array formula reduce ""\""\""\ - signs to #Missing, will it make ...
    By Maria J-son in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-05-2006, 08:25 AM
  8. [SOLVED] use variable in Workbooks("book1").Worksheets("sheet1").Range("a1"
    By Luc in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-28-2005, 04:05 PM

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