Multiple Row Formula

VbaHell

Well-known Member
Joined
Jan 30, 2011
Messages
1,220
Hello all in Mr Excel land

This maybe a stupid question for people in the know but I need help on this please

The formula below is what I need

[With Range("B4:B"& LastRow)
.FormulaR1C1 = "=SUMIF(Suppliers!C1,RC1,Suppliers!C2)"
.Value = .Value
End With]

But I want to include this formula every fourth column

IE: "F,J,N,R" and so on until column "AG"

Is there a simple why to complete this please
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
something like
Code:
For i= 2 to 33 step 4
With Range(cells(4,i),cells(lastrow,i))
        .FormulaR1C1 = "=SUMIF(Suppliers!C1,RC1,Suppliers!C2)"
        .Value = .Value
    End With
Next i
 
Upvote 0
Try:
Code:
    Dim myCol As Long
    For myCol = 5 To 33 Step 4
        With Range(Cells(4, myCol), Cells(lastRow, myCol))
            .FormulaR1C1 = "=SUMIF(Suppliers!C1,RC1,Suppliers!C2)"
            .Value = .Value
        End With
    Next myCol
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0
Thanks Joe4

This also works, always interesting to see the slightly different approaches to solve the same issue
 
Upvote 0
If I understand this correctly, it's performing a SUMIF on the Suppliers sheet to match up on Column A with the summed values in Column B. The conditional value is taken from column A on the current sheet. This means that all values in columns F, J, N, R ... etc. will be exactly the same. Also, AG is column 33 so shouldn't have the formula/value inserted. In that case you can possibly make this quicker by not re-performing the calculation each time:

Code:
Dim ThisCol As Long
Dim StoredValues As Variant

With Range("B4:B" & LastRow)
    .FormulaR1C1 = "=SUMIF(Suppliers!C1,RC1,Suppliers!C2)"
    StoredValues = .Value
End With

For ThisCol = 2 To 34 Step 4 ' Decide on 34 or 30
    Range(Cells(4, ThisCol), Cells(LastRow, ThisCol)).Value = StoredValues
Next ThisCol

WBD
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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