+ Reply to Thread
Results 1 to 4 of 4

Help with procedure to autosum a range in a worksheet with a variable number of rows.

  1. #1
    Registered User
    Join Date
    07-29-2014
    Location
    Copenhagen, Denmark
    MS-Off Ver
    2007
    Posts
    2

    Help with procedure to autosum a range in a worksheet with a variable number of rows.

    Hi all

    I am just starting out writing Macros with VBA and I have hit a brick wall with my first little project.

    My aim is to develop a procedure to autosum a range in a worksheet with a variable number of rows each time i work with this type of worksheet (a file exported from a financial program)

    I know that the range will always start in H9.

    I had hoped this would do the trick, but I get the error message: method range of object _global failed.

    Here is my code:

    Sub SalesTotal()
    Dim Sales As Long
    Sheets("SalesSheet").Activate
    Range("H9").Select
    Sales = Range(Selection, Selection.End(xlDown)).Select
    TotalSales = WorksheetFunction.Sum(Range("Sales"))
    End Sub
    I will be gratefull for any help in the matter.

    Cheers

    GröFaz
    Last edited by GröFaz; 07-29-2014 at 07:54 AM.

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Help with procedure to autosum a range in a worksheet with a variable number of rows.

    Please use code tags when posting. See Forum Rule No. 3. Does this help?

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    07-29-2014
    Location
    Copenhagen, Denmark
    MS-Off Ver
    2007
    Posts
    2

    Re: Help with procedure to autosum a range in a worksheet with a variable number of rows.

    Hi

    Thank you very much. That sub did the trick.

    And thank you for the heads up regarding the forum rules.

    GröFaz

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Help with procedure to autosum a range in a worksheet with a variable number of rows.

    You're welcome. Glad to help out and thanks for the feedback.

+ 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. Macro to Autosum variable rows above selected cell
    By Stratfordoaks in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 11-24-2012, 01:46 PM
  2. Copy a variable number of rows and columns to last row of another worksheet
    By SSGMiami in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-07-2011, 10:46 AM
  3. Using Autosum at the bottom of a variable range
    By MGT2000 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-09-2008, 10:37 PM
  4. Copying range to variable number of rows
    By nospaminlich in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-01-2005, 07:40 PM
  5. count number of rows (variable range)
    By Acid-Sky in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-23-2005, 06:05 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