+ Reply to Thread
Results 1 to 2 of 2

Sumif within loop

  1. #1
    Steph
    Guest

    Sumif within loop

    Hi. I have some code that loops through all cells in column A, and if a
    cell is not blank, it inserts a Sumif formula. But I can't figure out how
    to code the Criteria part of the formula to be Column A, Row whatever row
    the loop is currently on. So in the code below, I need to replace $A11
    within the formula with A & current row in the loop. Any ideas?

    Dim cl As Range
    Dim os As Integer

    os = Range("C2").Value
    For Each cl In Range("A:A")
    If Not IsEmpty(cl) Then
    ActiveCell.Offset(0, os).Resize(1, 13).Formula = _
    "=SUMIF(Data!$A$7:$A$1000,$A11,Data!D$7:D$1000)"
    End If
    Next cl



  2. #2
    Tom Ogilvy
    Guest

    RE: Sumif within loop

    Dim cl As Range
    Dim os As Integer

    os = Range("C2").Value
    For Each cl In Range("A:A")
    If Not IsEmpty(cl) Then
    ActiveCell.Offset(0, os).Resize(1, 13).Formula = _
    "=SUMIF(Data!$A$7:$A$1000,$A$" & cl.row & ",Data!D$7:D$1000)"
    End If
    Next cl

    --
    Regards,
    Tom Ogilvy


    "Steph" wrote:

    > Hi. I have some code that loops through all cells in column A, and if a
    > cell is not blank, it inserts a Sumif formula. But I can't figure out how
    > to code the Criteria part of the formula to be Column A, Row whatever row
    > the loop is currently on. So in the code below, I need to replace $A11
    > within the formula with A & current row in the loop. Any ideas?
    >
    > Dim cl As Range
    > Dim os As Integer
    >
    > os = Range("C2").Value
    > For Each cl In Range("A:A")
    > If Not IsEmpty(cl) Then
    > ActiveCell.Offset(0, os).Resize(1, 13).Formula = _
    > "=SUMIF(Data!$A$7:$A$1000,$A11,Data!D$7:D$1000)"
    > End If
    > Next cl
    >
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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