If
F2 = week number as criteria
and
G2 = Column header as criteria
try
in your caseCode:=SUMIF($A$3:$A$11,">="&F2,INDEX($B$3:$D$11,0,MATCH(G2,$B$2:$D$2,0)))
Code:=SUMIF($A$3:$A$11,">="&29,INDEX($B$3:$D$11,0,MATCH("Data 3",$B$2:$D$2,0)))
Hello,
I am trying to find week number in C1 and match it in column A. Then sum all cells below to the end in column D. In this example it is sum of D8:D11.
Is this possible to do?. The week number is going to be changing and would want to know the remaining amount for remaining weeks basically.
It is basically a vlookup but how to do it to include a sum of all cells below also?,
Please help
A B C D 1 Current Week 29 2 Week Data 1 Data 2 Data 3 3 24 1 1 1 4 25 2 2 2 5 26 3 3 3 6 27 4 4 4 7 28 5 5 5 8 29 6 6 6 9 30 7 7 7 10 31 8 8 8 11 32 9 9 9
Last edited by Addictions; Jul 20th, 2019 at 10:57 AM.
If
F2 = week number as criteria
and
G2 = Column header as criteria
try
in your caseCode:=SUMIF($A$3:$A$11,">="&F2,INDEX($B$3:$D$11,0,MATCH(G2,$B$2:$D$2,0)))
Code:=SUMIF($A$3:$A$11,">="&29,INDEX($B$3:$D$11,0,MATCH("Data 3",$B$2:$D$2,0)))
Last edited by navic; Jul 20th, 2019 at 11:24 AM.
VBA solution:
Code:Option Explicit Sub WeekSum() Dim lr As Long, crit As Integer, i As Long, x As Long lr = Range("A" & Rows.Count).End(xlUp).Row crit = Range("C1").Value2 For i = 3 To lr If Range("A" & i) = crit Then x = Application.WorksheetFunction.Sum(Range(Cells(i, 4), Cells(lr, 4))) End If Next i MsgBox ("Results of Sum equals " & x) End Sub
Let me know if that works for you
Alan
Am Yisrael Chai
Win 10--Office 2019
When Posting Code, please use code tags.
How to insert Mcode to Power Query https://excel.solutions/2017/11/powe...te-code-video/
Wow, Thank you so much for helping out on this one.
I need to break it down now and analyse how this exactly works.
Thank you again for your help!
I also really much appreciate VBA solution for this.
Thank you awesome people to help me out!.
Please could you possibly explain what ">="&29 really does in this formula?
Especially this bit ">="&. Why greater and equal is in quotes and it follows with and symbol afterwards.
Also how could I implement here COOUNTA to know the number of weeks calculated instead of having a total of numbers.
Last edited by Addictions; Jul 20th, 2019 at 11:39 AM.
I'll try to explain the formula, but keep in mind that English is not my mother tongue.
To be clearer you need to know the arguments of the SUMIF function.
Functions arguments are separated by delimiter (,) or (; ).Code:=SUMIF(range,criteria,sum_range)
"range" argument, in this case is '$A$3:$A$11'. It contains the first condition ie. Row header (week number 29).
"criteria" argument in this case week number 29 as condition. Since you want to add up the value of belonging to a number of week, the number 29 is set.
If you want to add up all the below number 29, therefore we want to add multiple conditions or numbers, ie. all the numbers more than 29.
This criterion consists of three parts.
The first part is text string ">="
Second part concatenate. For this purpose, you can use the '&' character (ampersand) that concatenate two or more values from multiple cells to produce one continuous text value.
The third part is the value from cell 'F2'.
So the results for these two terms are the same.
orCode:">="&F2
If you use the 'F9' key when evaluating the formula, then you will see that the result isCode:CONCATENATE(">=",F2)
"sum_range" argumentCode:">=29"
When a formula finds a condition, using the INDEX function as a result it returns a value from the same row but from a specified column that has a specified header. In this case, it is 'Data 3' located in the 'G2' cell as a condition.
The result of the INDEX function is a value of 10, from the column with the header 'Data 3'.Code:INDEX($B$3:$D$11,0,MATCH(G2,$B$2:$D$2,0)
Nested MATCH function returns the number of column for the condition (in this case 3).
So the SUMIF formula will return the SUM of all cells from the third column, which in column 'A' have number 29 and higher.
So, the SUM of values in the rows of 8 to 11.
I hope I have explained to you. If I'm not, then somebody on the forum will do it for me instead.
Last edited by navic; Jul 20th, 2019 at 12:43 PM.
It does explain. Thank you for help
You're welcome
Like this thread? Share it with others