Selective Sum of every Nth row given interval, range, and check variable

MallMan

New Member
Joined
Jul 1, 2022
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Howdy, not new to coding but new to VBA.
I have made a sample version of the data I'm working with below.

CodeLabel 1Label 2Label 3Label 1Label 2Label 3Label 1Label 2Label 3
20500161
20000252
20000343
20500434
20500525
20000616


My goal is to create a function that will sum all values from the label 3 columns, given that they have the specified code. My current thought process for this is to take the Range (User Defined selection of cells. In this case a box from the top 20500 to the bottom right 6), the step (every 3 in this case), and the check value/ variable (20500 or 20000 in this case) and try to complete this using that.

My thoughts were to have a grand total that is added to as rows/columns are indexed through in a for loop but I haven't been able to make this work.

How should I go about this?

Thank you in advance!
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Hummm...
My goal is to create a function that will sum all values from the label 3 columns, given that they have the specified code.
Maybe I didn't get your question, but such a function is already available in Excel and is named SUMIF; so, assuming "Code" is in column A and Label3 is D, you get the result using
Excel Formula:
=SUMIF(A2:A1000,20500,D2:D1000)
If your question was another one, then try explaining it again
 
Upvote 0
This partially works but my issue is that I have a potentially infinite number of label 3 columns. I need to check and sum columns D, G, J, M, and so on to take the numbers from all of them.

So if a function were to work properly, searching for 20500, it would return (1+6+1+4+3+4+5+2+5) 31.

Thank you for your help!
 
Upvote 0
Try one of these two:
1-Short
Excel Formula:
=SUM(IFERROR((B1:M11)*(A1:A11=20500)*(B1:M1="Label 3"),0))


2-Longer, but maybe easier to adapt
Excel Formula:
=LET(BigArr,A1:M11,myCode,20500,myHead,"Label 3",Code,INDEX(BigArr,0,1),Heads,INDEX(BigArr,1,0),SUM(IFERROR(BigArr*(Code=myCode)*(Heads=myHead),0)))
In this second formula the parametres are at the beginning of the formula
 
Upvote 0
Solution
Try one of these two:
1-Short
Excel Formula:
=SUM(IFERROR((B1:M11)*(A1:A11=20500)*(B1:M1="Label 3"),0))


2-Longer, but maybe easier to adapt
Excel Formula:
=LET(BigArr,A1:M11,myCode,20500,myHead,"Label 3",Code,INDEX(BigArr,0,1),Heads,INDEX(BigArr,1,0),SUM(IFERROR(BigArr*(Code=myCode)*(Heads=myHead),0)))
In this second formula the parametres are at the beginning of the formula
The first version worked for me, thank you so much for your help!
 
Upvote 0
Thank you for the feedback.
The second formula do the same thing, but in a syntax available in MS 365 that theoretically is easier to mantain, as the "parametres" are outside the final computatation: SUM(IFERROR(BigArr*(Code=myCode)*(Heads=myHead),0))
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,551
Members
449,088
Latest member
davidcom

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