+ Reply to Thread
Results 1 to 6 of 6

Macro to do Calculations on a dynamic Range

  1. #1
    Registered User
    Join Date
    08-16-2010
    Location
    us
    MS-Off Ver
    Excel 2007
    Posts
    21

    Macro to do Calculations on a dynamic Range

    I have a spreadsheet that I need to break the data into sections. I am doing this by subtotals. Once I have those subtotals, I want to do some calculations based on each section.
    Where I am having trouble is how do I do my calculation when each section is a dynamic range?
    For example – my first section maybe from row 2 – 84. Under that one calculation I need to apply is =sumif(D2:D84,”<0”,C2:C84)
    My next section may start at row 88 – 124.
    These rows vary from section to section and report to report.
    Please let me know how to set up a dynamic range/calculation. Thank you

  2. #2
    Valued Forum Contributor
    Join Date
    10-17-2010
    Location
    Nottingham, England
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013, 2016, 2019, 365
    Posts
    294

    Re: Macro to do Calculations on a dynamic Range

    Would be helpful to have an example spreadsheet with some explanation. From your description, I suspect a helper column and a pivot table might be the way to go, but difficult to tell without a full description (e.g. what determines which rows to do which calc...?)

  3. #3
    Registered User
    Join Date
    08-16-2010
    Location
    us
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Macro to do Calculations on a dynamic Range

    The attached file is a sample of the data.
    what I was doing, or trying. I am subtotaling by the letters in column I. From there I was doing a Cell Find What to look for the Letter total. e.g. A Total
    After that would be found, I was doing an offset to get over to the cell I wanted to do the calculations.
    My problem is at this point, how to run calculations when each section of data has a different number of rows.

    To answer your last question. After every letter total that is found, the same calculations that are going to be done in the first section, would get applied to every section.
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor
    Join Date
    10-17-2010
    Location
    Nottingham, England
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013, 2016, 2019, 365
    Posts
    294

    Re: Macro to do Calculations on a dynamic Range

    Still need a bit more clarification. As I understand it, you need something that will do the following.

    "For all rows that have an A in column I, do...." **what**?
    "For all rows that have a D in column I, do the same"
    "For every other type of entry in column I, do the same"

    Is that correct?

    And can you clarify **what** above?

  5. #5
    Registered User
    Join Date
    08-16-2010
    Location
    us
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Macro to do Calculations on a dynamic Range

    I attached another file to show you what I am doing in just one category.

    Other than the calculations that are posted in the attached file, if column D's total would equal 0, then I would need to take the percent from category D and apply it to my total in column C
    Attached Files Attached Files

  6. #6
    Valued Forum Contributor
    Join Date
    10-17-2010
    Location
    Nottingham, England
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013, 2016, 2019, 365
    Posts
    294

    Re: Macro to do Calculations on a dynamic Range

    I notice your profile says you are using Excel 2007. Is that correct? If so, I believe the attached does what you want, using the SUMIFS function, which was not available to the 2003 version.

    You'll also see that I have extracted a VLOOKUP into its own cell (so you can see what's going on) - this extracts the category D average for use in column Q.

    The calculations are the same as at the bottom of your single-category sheet, and I think I've interpreted the comment about Category D average - but if not, this should still give you some ideas.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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