+ Reply to Thread
Results 1 to 10 of 10

Formula to solve a complex chemistry equation

  1. #1
    Registered User
    Join Date
    10-13-2022
    Location
    Northamptonshire, England
    MS-Off Ver
    Excel 2016
    Posts
    56

    Formula to solve a complex chemistry equation

    I am working with the following equation

    V_b= V_a [(C_a/(1+([H^+])⁄K_a ) - [H^+] + K_w/([H^+]))/(C_b/(1+K_w⁄([H^+]K_b )) + [H^+ ] - K_w/([H^+]))]

    C_a, C_b, K_a, K_b, K_w and V_a are all constants or have known values. I want to set up a range of values for V_b from which to calculate [H^+ ]. This is not a trivial problem and I need to know how the calculation can be performed.

    Maybe using the Solver add-in (perhaps not) or by writing code in VBA. If the latter I would need help in writing the code because I am not a mathematician.

    Expected result for C_a = 0.1, C_b = 0.1, K_a = 1.74E-5, K_b = 0.63, K_w = 1.0E-14, V_a = 25, [H^+] = 1.95E-9 is V_b = 25 (or close to)

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,943

    Re: Formula to solve a complex chemistry equation

    Open this file with macros enabled. Enter the values you have into everything except the yellow cell - an initial guess for H+ - and then press the button. The result is dependent on your intial guess because the formula is not linear.

    The macro uses goal seek to solve your equation.

    Once you set up your tabular list of values - I assume that all the parameters are open to being changed - I can modify the macro to set up the values in column B and solve the equation, and then write the resulting value into your table. Just add your table to my workbook (with headers) somewhere on the sheet and re-post it.
    Attached Files Attached Files
    Last edited by Bernie Deitrick; 10-13-2022 at 10:11 AM.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    10-13-2022
    Location
    Northamptonshire, England
    MS-Off Ver
    Excel 2016
    Posts
    56

    Re: Formula to solve a complex chemistry equation

    Thanks for that Bernie but I am not sure how to use that to fill in a series as in the attachment
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,943

    Re: Formula to solve a complex chemistry equation

    "I want to set up a range of values for V_b from which to calculate [H^+ ]."

    But your table has values for pH (which is not in your formula anywhere), H^+ (which you want to calculate), and V_b with ?s (but what you wanted to set to specific values).

    I would expect a table of V_b and perhaps other constants - so what is it that you actually want to calculate? The attached calculates V_b
    Attached Files Attached Files
    Last edited by Bernie Deitrick; 10-13-2022 at 11:09 AM.

  5. #5
    Registered User
    Join Date
    10-13-2022
    Location
    Northamptonshire, England
    MS-Off Ver
    Excel 2016
    Posts
    56

    Re: Formula to solve a complex chemistry equation

    Sorry for the confusion - I want to calculate V_b from given values of pH (or [H^+ ]). In other words I know what pH I want to achieve from that I can get [H^+ ] because pH is simply -log([H^+ ]) and I need to calculate the V_b which will give me the desired pH.

    I will need to be able to set different values for C_a, C_b, K_a, K_b and V_a. K_w is always constant. Thanks for your patience!

  6. #6
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,943

    Re: Formula to solve a complex chemistry equation

    I included a V-b calculating version as an attachment to my last post. You can make copies of the sheet to use different sets of constants.

  7. #7
    Registered User
    Join Date
    10-13-2022
    Location
    Northamptonshire, England
    MS-Off Ver
    Excel 2016
    Posts
    56

    Re: Formula to solve a complex chemistry equation

    That's absolutely great, many thanks. Now I would like to be able to do the reverse.
    In other words, calculate [H^+ ] for given values of V_b
    Attached Files Attached Files

  8. #8
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,943

    Re: Formula to solve a complex chemistry equation

    The calculation is really dependent on initial guess since there are multiple roots.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    10-13-2022
    Location
    Northamptonshire, England
    MS-Off Ver
    Excel 2016
    Posts
    56

    Re: Formula to solve a complex chemistry equation

    Many thanks for that Bernie - it's a great starting point for me take off from. I'd like to clarify a couple of points in the FindSolution2 code though.

    For Each rngC In Range(Range("F10"), Cells(Rows.Count, "F").End(xlUp))
    rngC.Offset(0, 3).GoalSeek Goal:=rngC.Value, ChangingCell:=rngC.Offset(0, 1)
    Next rngC

    1. Am I right in thinking that the code in red selects each cell from F10 down to the last non-empty cell and that's the purpose of .End(xlUp)?

    2. My understanding of the way GoalSeek works is this: Change the [H+] values in column G, perform the calculation in column I and repeat until the value in column F is achieved. Is that correct?

    3. I don't understand how clicking the button invokes the FindSolution2 code - there doesn't seem to be any code for the button (like Button_Click for example) that would call the FindSolution2 code.

    Lastly, it goes almost without saying, I am very grateful for all your help. I do appreciate the time and effort you have spent. If the rules allow, I would like to make a small contribution to your favourite charity as a token of my appreciation. Please let me know if I can do that.

  10. #10
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,943

    Re: Formula to solve a complex chemistry equation

    1. Exactly. It is often better to work from the bottom up instead of from the top down - single cells make top-down extensions select entire columns (which is bad )

    2. Yes - that is how goal seek works. It requires an initial guess and then makes small changes to that guess and sees which way the end result changes.

    3. The macro is assigned to the shape by right-clicking and choosing 'assign macro'. If you have existing code, that is often simpler than using the click event and calling the macro. (Really, just my preference.... I usually have the code done and tested before I add the button, and then I would need to remember what I used as the macro name!)

    Lastly - thank you, but that's not needed. Just pay it forward. 30-odd years ago, a lot of great Excel users helped me, so when you get good...

+ 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. [SOLVED] Need help with a complex formula I cant solve. Please help. Re-order column numbers.....
    By lagiosman in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-31-2021, 01:26 PM
  2. [SOLVED] the way we solve Solve equation. Can Excel solve this?
    By tta.akmal in forum Excel General
    Replies: 3
    Last Post: 08-10-2020, 07:49 AM
  3. Batch solve complex excel formula
    By levatus in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 02-01-2019, 02:27 PM
  4. I need to solve a complex power equation
    By mrideout in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-17-2015, 02:31 PM
  5. Replies: 1
    Last Post: 06-29-2012, 03:21 AM
  6. Formula help needed to solve equation?
    By excel45 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-02-2008, 08:31 AM
  7. [SOLVED] How do I make FORMULA TO SOLVE CURVE OR 2ND ORDER EQUATION?
    By HANY in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-25-2005, 09: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