+ Reply to Thread
Results 1 to 5 of 5

getting the sum in an unknow lenght and placing in another cell

  1. #1
    Forum Contributor
    Join Date
    04-16-2016
    Location
    bognor
    MS-Off Ver
    Pro-Plus 2016
    Posts
    153

    getting the sum in an unknow lenght and placing in another cell

    Hi all,

    I have this code for summing up the values in a column of an unknown lenght.With this code the sum will appear in the cell at the bottom of the column at the end of the figures being summed up.Is there a way I could get the sum and place it in another cell on the sheet J1 for example.Here is the code:

    Sub test()
    lastrow = Worksheets("Sheet1").Cells(Rows.Count, "B").End(xlUp).Row

    Range("B" & lastrow + 1).Formula = "=sum(B4:B" & lastrow & ")"

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: getting the sum in an unknow lenght and placing in another cell

    Hi,

    I always feel it's much better to have formula totals in a fixed cell above a varying range of rows since the formula need never change, just make sure it covers all the rows your likely to use. Or better still give the total cell a dynamic range name.

    If you want to put the formula in J1 then simply
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Or if you've created a dynamic range name for column B then

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Contributor
    Join Date
    04-16-2016
    Location
    bognor
    MS-Off Ver
    Pro-Plus 2016
    Posts
    153

    Re: getting the sum in an unknow lenght and placing in another cell

    Hi Richard,
    thanks for that,I placed ths code in a button but get the following message:
    Variable not defined
    and it highlights the word "LastRow" in the code function.Am I doing something wrong.
    Regards
    John

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: getting the sum in an unknow lenght and placing in another cell

    Hi,

    Stating the obvious I suppose but have you declared the LastRow variable?

    I rather inferred from your original post that since you were implying that the code worked and you just wanted to know how to place it somewhere else that yuo have it defined elsewhere and just not shown.

    However for a more detailed response upload the workbook so that we may see the request in context.

    Just as a matter of interest since I used to work in Barrow In Furness is your name an allusion to this?

  5. #5
    Forum Contributor
    Join Date
    04-16-2016
    Location
    bognor
    MS-Off Ver
    Pro-Plus 2016
    Posts
    153

    Re: getting the sum in an unknow lenght and placing in another cell

    Hello Richard,
    Thanks for that it works great now.The Barrow connection is where I was born and grew up,I moved to bognor in the 80's,just after the Chewits monster ate the bus depot

+ 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. unknow problem in my FOR NEXT loop
    By assafa in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-31-2015, 06:23 PM
  2. Unknow function
    By Keldion in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-20-2015, 03:09 PM
  3. [SOLVED] Copy specific lenght cell avlue to other sheet
    By Parth007 in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 02-12-2015, 07:15 AM
  4. Select Multiple Cells at one time based on the lenght of the cell content
    By rajesraja in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-02-2014, 10:39 AM
  5. Unknow Chart
    By Zimri in forum Excel General
    Replies: 3
    Last Post: 07-12-2012, 03:47 AM
  6. Replies: 2
    Last Post: 08-26-2008, 04:03 AM
  7. Unknow IF condition
    By chlado in forum Excel General
    Replies: 2
    Last Post: 09-01-2006, 10:41 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