+ Reply to Thread
Results 1 to 4 of 4

Adding up values and grand totals through vba

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-12-2011
    Location
    Hyderabad
    MS-Off Ver
    Excel 2016
    Posts
    270

    Adding up values and grand totals through vba

    Hi All

    I am generating certain number for a table. I am trying to write a vba code for numbers to be added row wise and column wise.
    I am unable to move the second row to add the values in column "O". Below is the code, can u tell me how to move to the next row
    so that sum is generated .

    Private Sub Command Button1_Click()
    Dim ab1 As Range
    Dim AB2 As Range
    Dim ab3 As Long
    Dim ab4 As Long
    Dim AB5 As Long
    Dim AB6 As Range
    
    'Random numbers
    For Each ab1 In Range("c2:n27")
    ab1.Offset(0, 0).Value = Application.WorksheetFunction.RandBetween(325, 956)
    Next ab1
    
    'Adding Values
    For Each AB2 In Range("o2:o27")
    AB2.Offset(0, 0).Value = Application.WorksheetFunction.Sum(Range("C2: N2"))    'From this point how will i move to the next row c3:n3 ???
    Next AB2
    End Sub
    Many thanx in advance
    Attached Files Attached Files
    Never confuse a single defeat to the final defeat.

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,049

    Re: Adding up values and grand totals through vba

    Why not just use a regular SUM() function?

    =SUM(C2:C27) for the columns, copied across
    =SUM(C2:N2) for the rows, copied down
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Forum Contributor
    Join Date
    02-12-2011
    Location
    Hyderabad
    MS-Off Ver
    Excel 2016
    Posts
    270

    Re: Adding up values and grand totals through vba

    well i just wanted to know how we do it in vba, and i also wanted to know how we move from one row to another row,
    i vaguely know it should be done through offset function / end(xlup) something like this.

  4. #4
    Forum Contributor
    Join Date
    02-12-2011
    Location
    Hyderabad
    MS-Off Ver
    Excel 2016
    Posts
    270

    Re: Adding up values and grand totals through vba

    All i wanted to do is add values in a single row (example from c2 to g2) and get the sum in h2
    and move to c3 to g3 and get the sum in h3.

    Any ideas ?

+ 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. Grand Totals to top of page
    By Cburrows in forum Excel General
    Replies: 4
    Last Post: 03-08-2012, 01:58 PM
  2. Method for calculating Invoice Totals and Grand totals
    By sahran4441 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-06-2010, 10:24 PM
  3. Replies: 4
    Last Post: 01-10-2008, 12:31 PM
  4. Can't get Grand Totals (rows) to appear
    By TonyG in forum Excel General
    Replies: 1
    Last Post: 05-23-2006, 10:06 PM
  5. Pivottable:adding grand totals
    By arthursdomain@gmail.com in forum Excel General
    Replies: 3
    Last Post: 12-06-2005, 06:10 PM

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