Macro Loop help

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.

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:

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Which column are your putting the formula in?
 
Upvote 0
In that case replace
Code:
ActiveCell.FormulaR1C1
with
Code:
Cells(x, 354).FormulaR1C1
 
Upvote 0

Forum statistics

Threads
1,215,206
Messages
6,123,636
Members
449,109
Latest member
Sebas8956

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top