+ Reply to Thread
Results 1 to 4 of 4

VBA sumifs with a loop

Hybrid View

  1. #1
    Registered User
    Join Date
    02-04-2018
    Location
    Canberra, Australia
    MS-Off Ver
    2013
    Posts
    77

    VBA sumifs with a loop

    Hi All,
    I want to write some code that will allow me to do a sumifs.

    How do I get the code to drop to the next line so 'Graph data'!A4' to changes to 'Graph data'!A5' within the code?

    Column A has the time of day, from 8am to 8pm and is the look up




    Current code looks like

    
    Sub GraphData()
    
    Sheets("GraphData").Select
    Range("B4:M724").clear
    
    Range("B4").select
    
    For I = 1 to 721
    
    Cells(3 + I, 2).Formula = "=SUMIFS(AAA!$F:$F,AAA!$A:$A,""=""&Graphs!$G$1,AAA!$B:$B,""=""&'Graph data'!A4)"
    Cells(3 + I, 3).Formula = "=SUMIFS(AAA!$G:$G,AAA!$A:$A,""=""&Graphs!$G$1,AAA!$B:$B,""=""&'Graph data'!A4)"
    Cells(3 + I, 3).Formula = "=SUMIFS(AAA!$H:$H,AAA!$A:$A,""=""&Graphs!$G$1,AAA!$B:$B,""=""&'Graph data'!A4)"
    
    Next I
    
    End Sub

    Data.JPG

    Any help appreciated

    Cheers

    Dean

  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: VBA sumifs with a loop

    Can't you just copy the formula you create with the Cells(3 + I, 2)......line of code and paste it to the rows underneath.

    I tend to hold formulae like this that need copying down a range in a named range in a spare row somewhere above the data and have VBA copy and paste the range name.
    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
    Registered User
    Join Date
    02-04-2018
    Location
    Canberra, Australia
    MS-Off Ver
    2013
    Posts
    77

    Re: VBA sumifs with a loop

    Thanks Richard,

    I'm not sure what you mean by

    'I tend to hold formulae like this that need copying down a range in a named range in a spare row somewhere above the data and have VBA copy and paste the range name. '

    [/I]

    I wanted to 'loop' as there is over 270 lines it needs to go through and ended up with 'Graph data'!A" & I + 3 & ")" in the formula.

    Cheers

    Dean

  4. #4
    Registered User
    Join Date
    02-04-2018
    Location
    Canberra, Australia
    MS-Off Ver
    2013
    Posts
    77

    Re: VBA sumifs with a loop

    I ended up adding " & I + 3 & ")" to the end of the formula - works a treat


    Cells(3 + I, 2).Formula = "=SUMIFS(AAA!$F:$F,AAA!$A:$A,""=""&Graphs!$G$1,AAA!$B:$B,""=""&'Graph data'!A" & I + 3 & ")"
    Cells(3 + I, 3).Formula = "=SUMIFS(AAA!$G:$G,AAA!$A:$A,""=""&Graphs!$G$1,AAA!$B:$B,""=""&'Graph data'!A" & I + 3 & ")"
    Cells(3 + I, 4).Formula = "=SUMIFS(AAA!$H:$H,AAA!$A:$A,""=""&Graphs!$G$1,AAA!$B:$B,""=""&'Graph data'!A" & I + 3 & ")"
    Cheers

    Dean

+ 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. Transform Sumifs using LOOP
    By Biplab1985 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-29-2017, 07:54 AM
  2. Replies: 0
    Last Post: 08-22-2017, 03:49 PM
  3. Convert Sumifs to vba code with loop
    By lakamas in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-13-2015, 06:33 PM
  4. VBA Sumifs Loop
    By SimonJF in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-08-2013, 12:18 AM
  5. Loop function SUMIFS
    By jnh0 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-05-2013, 12:35 PM
  6. SUMIFS Puzzle - Trying to avoid adding multiple SUMIFS to get valid result
    By haldavid in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-09-2013, 03:42 PM
  7. [SOLVED] Sumifs, problem with the formula: =sumifs(c10:c200,<=today(),0)
    By Faustocruz in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-08-2012, 04:26 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