+ Reply to Thread
Results 1 to 3 of 3

creating loop for SUM function with variables

  1. #1
    Registered User
    Join Date
    12-09-2009
    Location
    Belgrade
    MS-Off Ver
    Excel 2010
    Posts
    17

    Question creating loop for SUM function with variables

    Screen Shot 2019-12-06 at 04.50.46.png

    im trying to create macro that will SUM cells
    at the right end cell of columns in G column it should SUM numbers from D:F (green numbers)
    at the bottom cells in row 6 it should SUM numbers from 3:5
    bottom right cell should SUM green numbers

    in this example it's like this

    G3.Value = "=SUM(D3:F3)"
    G4.Value = "=SUM(D4:F4)"
    G5.Value = "=SUM(D5:F5)"

    D6.Value = "=SUM(D3:D5)"
    E6.Value = "=SUM(E3:E5)"
    F6.Value = "=SUM(F3:F5)"

    G6.Value = "=SUM(G3:G5)"

    this table will grow so macro would be very very helpfull
    there is no option to do it manually ... no time for that
    i'm trying to avoide human erorr

    i have the idea that i should set variables for first&last used row and first&last used column and then to sum only numbers
    but my knowleage stops there

    one thing that is very important for me is that cell needs to have =SUM function ... i can't use Application.Sum(Range) because sometimes it will happen that i need to change some numbers and i need live SUM update

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,482

    Re: creating loop for SUM function with variables

    Check it out.

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    12-09-2009
    Location
    Belgrade
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: creating loop for SUM function with variables

    Quote Originally Posted by davesexcel View Post
    Check it out.

    Please Login or Register  to view this content.
    hey ... tnx ... it's working
    BUT it's working only for this scenario
    this is going to be dynamic meaning i am going to have more columns and more rows with numbers so is it possible to make variable for columns also?
    sometimes it will have 3x3 sometimes 5x10 ... it's not going to be fixed table
    rw is looking for last row so how to make macro that will look for last used column and incorporate that in macro?

+ 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. Need help creating a loop for this function
    By opiu in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-24-2019, 08:11 PM
  2. Calling A Function With Variables based A Loop Within A Loop
    By Mark123456789 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-24-2016, 03:03 PM
  3. Creating string with for loop and if function - unexpected results
    By eg0e in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-22-2015, 10:15 AM
  4. [SOLVED] Creating a loop that copies values from one sheet to another based on an index function.
    By ndrobinson in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-27-2013, 06:19 PM
  5. Creating For Loop with 3 variables
    By BeefNoodleSoup in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-16-2012, 05:25 PM
  6. Creating a list of variables at the end of a For Each Loop
    By Mordred in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-13-2010, 05:03 PM
  7. Need help creating a function with loop.
    By gabethegrape in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-17-2009, 05:38 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