Sumif within loop

S

Steph

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top