+ Reply to Thread
Results 1 to 3 of 3

Evaluating an expression in Excel VBA macro

  1. #1
    Registered User
    Join Date
    09-25-2022
    Location
    USA
    MS-Off Ver
    2019
    Posts
    2

    Evaluating an expression in Excel VBA macro

    I have the following expression in cell A1 which is input

    Input:

    Please Login or Register  to view this content.
    And I want it to be evaluated as below and displayed in cells in Column B from B1 through B10:

    Output:

    Please Login or Register  to view this content.
    The input expression is variable and can have several such expressions. How do I approach the VBA macro code?

    Basically below are the rules for evaluation:
    1) There can only be these operators +, / , +- and brackets.
    2) If there is a "+" operator it should be evaluated as a "+" operator only. But will be evaluated for the entire expression each time.
    3) If there is a "/" operator it should be expanded for all variables in the expression individually. So an "A/B", should be individually expanded for A and B both.
    4) If there is a "+-" operator and there are expressions in bracket, they should be expanded individually as a "+" operator and only once. So +-(C+D) will be evaluated only once but after expansion as +C, +D, +C+D.
    Last edited by bud9; 09-25-2022 at 11:24 AM. Reason: To add rules for macro.

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,175

    Re: Evaluating an expression in Excel VBA macro

    What are "rules" for the (any) evaluation?
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  3. #3
    Registered User
    Join Date
    09-25-2022
    Location
    USA
    MS-Off Ver
    2019
    Posts
    2

    Re: Evaluating an expression in Excel VBA macro

    Sorry, I thought adding description of rules would be confusing so added input and outputs. Just edited the question to add rules.

+ 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. Excel evaluating value wrong
    By JoshNZ in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-07-2016, 05:05 AM
  2. Macro solves the mathematical expression
    By MrObvious in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-25-2014, 03:10 PM
  3. [SOLVED] Remove <IMG> with a regular expression & macro
    By ismael84 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-13-2013, 09:57 PM
  4. Formula evaluating itself 'on the fly' or a vba macro
    By dziabdak in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-26-2012, 09:29 AM
  5. Evaluating AND expression in a Do While loop
    By jerseyguy1996 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-12-2010, 10:02 AM
  6. [SOLVED] Expression for Macro - help
    By Pasmatos in forum Excel General
    Replies: 4
    Last Post: 11-28-2005, 03:10 PM
  7. Evaluating an expression...
    By CR in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-25-2005, 11:05 AM

Tags for this Thread

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