+ Reply to Thread
Results 1 to 5 of 5

Using loops to fill in table

  1. #1
    Registered User
    Join Date
    05-28-2019
    Location
    Edinburgh
    MS-Off Ver
    2013
    Posts
    92

    Using loops to fill in table

    Im trying to make a code to fill in a table for me. I thought about using loops to do it. However Im not sure on how to get it to do what I want. I understand the basics of loops. I think I would also use a loop to multiple the values together then select the next row down until it reads delta Hr or Delta Sr. I want the code to work if I change the number of products and reactants, however I only know how to code if the number was fixed. ie I would use activecell.offset(x,y) to select the cell and sum the values into it, but if the number of reactants and products changes this cell will also move. I have attached a spreadsheet containing the individual steps but am not sure how code for it.
    Attached Files Attached Files

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Using loops to fill in table

    Try

    B6

    =SUMPRODUCT(OFFSET(INDIRECT("A" & MATCH("Reactants",A:A,0)),0,1,COUNTIF(A:A,"Reactants"),1),OFFSET(INDIRECT("A" & MATCH("Reactants",A:A,0)),0,2,COUNTIF(A:A,"Reactants"),1))

    B7
    =SUMPRODUCT(OFFSET(INDIRECT("A" & MATCH("Reactants",A:A,0)),0,1,COUNTIF(A:A,"Reactants"),1),OFFSET(INDIRECT("A" & MATCH("Reactants",A:A,0)),0,3,COUNTIF(A:A,"Reactants"),1))

    Similarly for products.

    Hopefully this will get you started.

    Couldn't see a temperature term - is this already factored into your delta S value?
    Martin

  3. #3
    Registered User
    Join Date
    05-28-2019
    Location
    Edinburgh
    MS-Off Ver
    2013
    Posts
    92

    Re: Using loops to fill in table

    Thank you. How would I apply that to a general code rather than just putting it into the cells? Heres what Ive got so far:
    [CODE]Sub Gibbs()
    Range("c3").Select
    Do Until ActiveCell.Value = "Delta Hr Reactants"
    X = ActiveCell.Offset(0, 1) * ActiveCell.Offset(0, 2)
    ActiveCell.Offset(1, 0).Select
    Loop
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = 'SUM OF X VALUES
    End Sub
    /[CODE]
    Im not sure on how to write the part of the code that will sum the all the x values.
    Also Im this code will find gibbs at a reference temp and pressure of 1atm and 298K. Because at this temp and pressure most enthalpy and entropy values are known. I can then use this with the integrated vant hoff equation to find the position of equilibrium

  4. #4
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Using loops to fill in table

    Maybe

    [CODE]Sub Gibbs()
    Range("c3").Select
    Do Until ActiveCell.Value = "Delta Hr Reactants"
    X = X + (ActiveCell.Offset(0, 1) * ActiveCell.Offset(0, 2))
    ActiveCell.Offset(1, 0).Select
    Loop
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = X
    End Sub
    /[CODE]

  5. #5
    Registered User
    Join Date
    05-28-2019
    Location
    Edinburgh
    MS-Off Ver
    2013
    Posts
    92

    Re: Using loops to fill in table

    Thank you, that works prefectly

+ 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] Duplicate data for multiple cells by Auto Fill / Fill Down - Dynamic Table
    By ITY in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 07-23-2019, 09:57 AM
  2. Replies: 4
    Last Post: 05-11-2018, 04:35 PM
  3. Replies: 1
    Last Post: 05-10-2018, 08:28 AM
  4. Macro to fill 1st table with info from 2nd table. 2nd table search with 2 conditions
    By Ribeiro.JD in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-17-2016, 02:03 PM
  5. VBA speed performance issues with nested loops during import to table range
    By ggwp in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-29-2016, 09:16 AM
  6. Fill arrays from sheet / SUMIFS / create & fill table based on multiple criteria
    By Dimitris254 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-03-2016, 09:43 AM
  7. Table of Sines with Loops
    By bmr8002 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-29-2012, 09:25 AM

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