VBA code modification sumif

FGaxha

Board Regular
Joined
Jan 10, 2023
Messages
221
Office Version
  1. 365
Platform
  1. Windows
Hi,
I have a macro to sumif between column D and E to Column I and J.
I need to add more columns. D, E F,G,H to sumif to column I,J,K,L,M,N.

Option Explicit

Sub Sumiff()
Dim i As Integer
Dim lrow As Integer

lrow = Range("i16000").End(xlUp).row

For i = 2 To lrow

Range("j" & i).Value = Application.WorksheetFunction.Sumif(Range("d:d"), Range("i" & i), Range("e:e"))

Next i

Dim rng As Range

Set rng = Range("i1:j20")

With rng
.Font.Bold = True
.Font.Color = vbBlue


End With

End Sub
 

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
I need to add more columns. D, E F,G,H to sumif to column I,J,K,L,M,N.
You are not explaining, of those columns, which column is the range, which column is the criterion and which column contains the values to be sum.


Trying to deduce what you need, I put 2 more examples in your code. 🧙‍♂️
Just adjust the columns.
Rich (BB code):
  For i = 2 To lrow
    Range("j" & i).Value = WorksheetFunction.SumIf(Range("d:d"), Range("i" & i), Range("e:e"))

    Range("K" & i).Value = WorksheetFunction.SumIf(Range("D:D"), Range("I" & i), Range("F:F"))
    Range("L" & i).Value = WorksheetFunction.SumIf(Range("D:D"), Range("I" & i), Range("G:G"))
    '...
  Next i

If you have difficulties, give an example with a minisheet using the xl2bb tool and explain how you want each sum.

----- --
I hope to hear from you soon.
Respectfully
Dante Amor
----- --
 
Upvote 1
Solution

Forum statistics

Threads
1,215,096
Messages
6,123,074
Members
449,093
Latest member
ripvw

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