+ Reply to Thread
Results 1 to 6 of 6

Can a cell contain text and perform calculation?

  1. #1
    Forum Contributor
    Join Date
    04-30-2009
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    496

    Can a cell contain text and perform calculation?

    Hello all. In trying to tame a Hydra (mythical monster that regenerates heads when they are cut off...seems the more I work on this, the more things I need to incorporate) of a project. I have posted several questions that many of you Excel Wizards are helping me with...and here is another...

    I would like to have a cell in which there is descriptive text and the results of a calculation. For example, in row 2, I want to state the current total number of items in inventory at the top of the sheet in the center of the used cells.

    Inventory Total is: SUM(A4:A64,000) as of: Date()

    I can't merge cells or manipulate the text in such a way to neatly bring the text and calculation together. And there are actually 2 calculations in the example above. One to SUM the items and one to add the date. Can this be done and can someone help me with the code?

    Thanks,
    Andrew
    Last edited by drewship; 11-18-2009 at 02:43 PM.

  2. #2
    Registered User
    Join Date
    12-22-2003
    Location
    Texas
    Posts
    90

    Re: Can a cell contain text and perform calculation?

    you can. try this
    ="Inventory Total: "&sum(a4:a64)&" as of "&Month(today())&"/"&day(today())&"/"&year(today())
    Last edited by barrfly; 11-17-2009 at 04:00 PM.
    Barrfly

  3. #3
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Can a cell contain text and perform calculation?

    Instead of

    Month(today())&"/"&day(today())&"/"&year(today())

    I'd recommend just

    TEXT(TODAY(),"mm/dd/yyyy")

  4. #4
    Forum Contributor
    Join Date
    04-30-2009
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    496

    Re: Can a cell contain text and perform calculation?

    Thanks barrfly and Paul!! They both work perfectly. Other than smaller code, what is the difference between the 2?
    Also, is there a way that I can make the

    sum(a4:a64)

    RED and BOLD font?

    Thanks again!!
    Last edited by drewship; 11-18-2009 at 09:40 AM.

  5. #5
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Can a cell contain text and perform calculation?

    The only real difference is the number of calculations each method uses.

    Barrfly's method gets the value for the TODAY() function three times, then gets the MONTH, DAY and YEAR values in three more functions, and then concatenates it all resulting in a text string of the current date.

    My method gets the value of TODAY() just once, and then uses the TEXT function to present it in the specified format. So two functions instead of seven. In a small set of data you likely wouldn't notice a difference, but if you had 500,000 rows it would likely be noticeable.

    As for making parts of a function a different format than the rest, this cannot be done using formulas. Even using VBA you couldn't maintain the formula in the cell and do that, you'd have to convert the formula's result into a static value, and then you could format any or all of it. (Because the VBA would replace the formula with the static value, if you changed the values in A4:A64, the result cell would not get updated - until you ran the macro again, of course.

  6. #6
    Forum Contributor
    Join Date
    04-30-2009
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    496

    Re: Can a cell contain text and perform calculation?

    Thanks Paul. You have been a big help!!

    Andrew

+ 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