Consulting

Results 1 to 3 of 3

Thread: Perform basic operations basen on a cell

  1. #1

    Perform basic operations basen on a cell

    Thought this was a simple matter. I want the cell to perform the formula based on what operation is specified in another cell.

    2 + 2 4
    2 - 2 0
    2 / 2 1
    2 * 2 4

    I want someting like this =A1&B1&C1.
    i can get aroung this problem with
    =OM(B1="+";A1+C1;OM(B1="-";A1-C1;OM(B1="/";A1/C1;OM(B1="*";A1*C1)))

    Is there any other solution to this?

  2. #2
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,198
    Location
    You can try the below:

    In the ribbon go to: Formulas / Name Manager
    Click 'New'
    Put: EVAL in the 'Name' box
    In the 'Refers to' box put: =LAMBDA(x, EVALUATE(x))

    Then in your spreadsheet you can use the EVAL function you created as below:
    =EVAL(A1&B1&C1)
    EDIT: Forgot to mention, this may only work on Excel 365
    Last edited by georgiboy; 10-06-2023 at 02:43 AM.
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  3. #3
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,198
    Location
    If you are using an older version of Excel then you could use a small UDF:
    Function CalcTextFormula(v1 As String, op As String, v2 As String)
        CalcTextFormula = Evaluate(v1 & op & v2)
    End Function
    Used in the spreadsheet like:
    =CalcTextFormula(A1,B1,C1)
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

Posting Permissions

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