+ Reply to Thread
Results 1 to 3 of 3

Macro to stop running at last row

  1. #1
    Registered User
    Join Date
    11-22-2008
    Location
    house
    Posts
    68

    Macro to stop running at last row

    Hi there

    I have a spreadsheet containing a macro to automatically sum values from week to week and display the max/min and average. This is almost fully working. The problem I have is the macro copies the sum formula down the page and doesn't stop at the last row. It always adds one or two extra rows.

    The formula should stop at row 77 however this does not happen and therefore the sum keeps going. Which in turn, distorts the max/min figures.

    I am really stumped how to sort this out
    Thanks
    Attached Files Attached Files
    Last edited by staples; 08-10-2009 at 01:52 PM.

  2. #2
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Macro to stop running at last row

    Firstly, there are no macros in your workbook, just formulas.

    Second - NEVER reference an entire column in a formula.

    Your problem is easily solved by using a Dynamic Named Range as the range reference in the formulas. Dynamic Named Range automatically expand/contract as data are added/deleted in the range.

    In your workbook, the following dynamic named ranges were created and used:
    Holdings: =OFFSET('Report 1'!$C$1,0,0,COUNTA('Report 1'!$C:$C),1)
    WeeklySum: =OFFSET(Holdings,0,1)

    Amended formulas
    Max: =MAX(WeeklySum)
    Min: =MIN(WeeklySum)
    Average: =AVERAGE(Holdings)

    TIP: never change the horizontal alignment of a data cell. By default Excel right aligns all numeric values and left-aligns all text values. By using these default horizonal alignments you can tell at a glance if cell contents are numeric and text.
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    11-22-2008
    Location
    house
    Posts
    68

    Re: Macro to stop running at last row

    Thanks for the reply, that's working great now.

+ 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