Results 1 to 9 of 9

Thread: How to Write Formula Using Formula

  1. #1

    Thread Starter
    Addicted Member LeonX's Avatar
    Join Date
    Dec 2004
    Location
    Jakarta, Indonesia
    Posts
    172

    Question How to Write Formula Using Formula

    Hi ...
    I have question about excel.

    I'm curious how can we write a formula using another formula?
    Example:
    In cell A1 I have value | 10 |
    In cell B1 I have value | 10 |
    In cell C1 I have value | =concatenate("=",A1,"+",B1) |

    It will give me result in cell C1 | =10+10 |, is this possible if I want the result in cell C1 | 20 |? But not by typing formula | =A1+B1 | in cell C1.

    Hope everyone understand my question.
    Thanks for helping me solve this problem.
    Last edited by LeonX; Mar 23rd, 2005 at 04:40 AM.
    Regards,
    Ferry

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: How to Write Formula Using Formula

    uhhh

    Where do you want the result?
    If its another cell, just put the formula in that cell of a1+b1
    If you mean via code you'd need something like the following:
    Code:
    debug.print activeworkbook.activesheet.cells(1,1)+activeworkbook.activesheet.cells(1,2)
    Of course its easier to have variables for the workbook and sheet.
    Code:
    dim wrk as workbook, sht as worksheet
    
    set wrk = activeworkbook
    set sht = wrk.activeworksheet 'or wrk.sheets("sheetname")
    
    debug.print sht.cells(1,1)+sht.cells(1,2)
    
    set sht=nothing
    set wrk=nothing

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3

    Thread Starter
    Addicted Member LeonX's Avatar
    Join Date
    Dec 2004
    Location
    Jakarta, Indonesia
    Posts
    172

    Re: How to Write Formula Using Formula

    sorry for making you confuse Ecniv ...

    i will make it simple , can i evaluate formula | =concatenate("=",A1,"+",B1) | as a formula.

    this | =concatenate("=",A1,"+",B1) | will give result | =10+10 | right.

    i want the result from | =concatenate("=",A1,"+",B1) | become | 20 | maybe with another function like
    | =EVALUATEASFORMULA(concatenate("=",A1,"+",B1)) |, my question, is there any function in excel like EVALUATEASFORMULA?
    Regards,
    Ferry

  4. #4
    Addicted Member
    Join Date
    Jan 2002
    Location
    Glasgow, Scotland
    Posts
    202

    Re: How to Write Formula Using Formula

    I think what you are trying to do is use the cell values as a formula.

    and use those values to get a result.

    seems a bit unecessary.

    maybe if you explain your reasons for needing to do this, it would be easier to suggest a resolution.
    if you fail to plan, you plan to fail

  5. #5
    Lively Member
    Join Date
    Jun 2003
    Location
    france
    Posts
    71

    Re: How to Write Formula Using Formula

    did you tried to code something like this
    VB Code:
    1. formule = "=gauche(A2" & Chr(59) & "4)"
    2. Range("A1").FormulaLocal = formule

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: How to Write Formula Using Formula

    Before everyone pulls their head out of their arse and realize that it isn't truly VBA that you are doing here, but an Excel FORMULA.... See if you can do this:

    =Eval (concatenate("=",A1,"+",B1))

    I've not done this my self, and not sure why you would want to, but I think that will work.

    Tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7

    Thread Starter
    Addicted Member LeonX's Avatar
    Join Date
    Dec 2004
    Location
    Jakarta, Indonesia
    Posts
    172

    Re: How to Write Formula Using Formula

    thanks to techgnome, writelearner, Br1an_g, and everyone here, ...

    4 techgnome:
    i've already try your code but it didn't work.

    4 writelearner:
    i want to know the pure excel function not the vba.

    4 Br1an_g:
    for now i don't have any reason to do that, just curious.
    Regards,
    Ferry

  8. #8
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: How to Write Formula Using Formula

    I don't get your problem.
    you want to get the result 20 in cell C1, but you don't want to put in the formula "=a1+b1". What do you want to put into that cell?? can you give an example??
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to Write Formula Using Formula

    eval is not supported in Excel but it does have an Evaluate function. But again, its VBA
    and not valid as a formula input.

    I dont understand the reasoning behind this. You want to add to cells together but not using
    a formula or vba code?

    Or are you trying to place a "formula text" in a cell but not as a formula. Then read the text formula
    and put the resulting value of that "formula" into another cell?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

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



Click Here to Expand Forum to Full Width