hoosier1598
New Member
- Joined
- May 25, 2018
- Messages
- 2
Hi,
I am trying to fill in a formula (depending on the if then statement) down an entire column.
My macro works for my first selected cell but does not continue down to the last row. I want the logic to continue down through until the last row. My macro is below.
Thank you!!!!
I am trying to fill in a formula (depending on the if then statement) down an entire column.
My macro works for my first selected cell but does not continue down to the last row. I want the logic to continue down through until the last row. My macro is below.
Code:
Dim sht As Worksheet
Dim LastRow As Long
Set sht = ActiveSheet
lr = sht.Range("MP7").CurrentRegion.Rows.Count
selrow = Selection.Row
For x = 7 To lr
If sht.Cells(x, 14) = sht.Cells(x, 15) Then
ActiveCell. _
FormulaR1C1 = "=SUM(SUMPRODUCT(('[PMA Weekly Production Current Week.xlsx]data'!R1C2:R50066C2=""CMD"")*('[PMA Weekly Production Current Week.xlsx]data'!R1C16:R50066C16=RC15)*('[PMA Weekly Production Current Week.xlsx]data'!R1C5:R50066C5=R3C),'[PMA Weekly Production Current Week.xlsx]data'!R1C26:R50066C26))"
Else
ActiveCell.FormulaR1C1 = _
"=SUM(SUMPRODUCT(('[PMA Weekly Production Current Week.xlsx]data'!R1C2:R50066C2=""CMD"")*('[PMA Weekly Production Current Week.xlsx]data'!R1C16:R50066C16=RC15)*('[PMA Weekly Production Current Week.xlsx]data'!R1C5:R50066C5=R3C),'[PMA Weekly Production Current Week.xlsx]data'!R1C26:R50066C26),SUMPRODUCT(('[PMA Weekly Production Current Week.xlsx]data'!R1C2:R50066C2=""" & _
"CMD"")*('[PMA Weekly Production Current Week.xlsx]data'!R1C16:R50066C16=RC14)*('[PMA Weekly Production Current Week.xlsx]data'!R1C5:R50066C5=R3C),'[PMA Weekly Production Current Week.xlsx]data'!R1C26:R50066C26))" & _
""
End If
Next x
End Sub
Thank you!!!!
Last edited by a moderator: