Given a column of numeric values, is it possible to sum values until the total reaches a particular threshhold, then reset the sum total and continue? for example
Val Sum
103
52 155
47
60
103 210
100
76 176
163 163
169 169
87
103 190
84
31
59 174
87
49
67 203
This sums groups of numbers until the value exceeds 150, then resets the counter.
i'll post it more for the proof of concept than a real answer or for the case i could improve this (Issun may have an idea too).
Here it is:
Let assume your Val is in column A and Sum in column B and Titles are in row 1.
In column C, we will set a formula that will tell which is the "last" cell where you sumed it up > in cell C3, put:
{=MAX(IF($B$2:B2=0;0;ROW($B$2:B2)))}
This is an array formula, you will have to validate with CtrlShiftEnter.
In cell B3, you will have to put the first value (155 in your example), sorry, i didn't find a proper workaround.
In cell B4, put:
=IF(SUM($A$1:A4)-SUM(INDIRECT("$B$1:"&ADDRESS(C4;2)))>150;SUM($A$1:A4)-SUM(INDIRECT("$B$1:"&ADDRESS(C4;2)));0)
Then drag & drop the formulas till the end of your values.
[EDIT] Actually, you could put it all in a single formula in cell B2:
{=IF(SUM($A$1:A2)-SUM(INDIRECT("$B$1:"&ADDRESS(MAX(IF($B$1:B1=0;0;ROW($B$1:B1)));2)))>150;SUM($A$1:A2)-SUM(INDIRECT("$B$1:"&ADDRESS(MAX(IF($B$1:B1=0;0;ROW($B$1:B1)));2)));0)}
and drag and drop it till the end of your values. Seems to work too.
Simplest way to do it (no need for array formulas let alone VBA):
In B2, type =IF(B1<150,B1+A2,A2) and drag down. This will sum until it reaches 150 or more, and then restart at zero. Of course, the intermediate sums (i.e. on the way up to 150) will show as well. If this bothers you, a couple of options spring to mind:
Type =IF(B2>=150,B2,"") in C2 and drag down, and hide column B.
Apply conditional formatting to column B such that numbers below 150 get shown in white font.
Here's a solution in VBA (sorry I know you wanted a forumula). You can obviously tweat the range to be whatver you need it to be. Please note I used LONG as data type (and I am casting to long to avoid some errors), but you need to use DOUBLE if you have any floating point numbers.
Sub SumIt()
Dim cell As range
Dim currentCount As Long
For Each cell In range("A2:A100")
currentCount = currentCount + CLng(cell.Value)
If currentCount > 150 Then
cell.Offset(0, 1).Value = currentCount
currentCount = 0
End If
Next
End Sub
How it works: I loop through each cell in the range and add the value to a variable called currentCount. I then check if it's over 150, if it is I paste the currentCount to the B column (same row) and reset the count and move to the next cell. Simple!
Related
I want range for specific value in excel as,
my values in column A
122.7
250.6
377.9
507.1
635.3
761.1
892.7
1021.5
1154.7
1284.7
my values in column B
50
100
150
200
250
300
350
400
450
500
I have to compare value is 533 in A column. If 533 is value then it should return range 507.1 and 635.3 in separate row for further calculations. (e.g Similarly I input value is 210 then it should return range 122.7 and 250.6 in separate row.)
for further calculations,value which we got from above 507.1 and 635.3 should take value from Corresponding column B i.e value of 200 and 250 in separate row (e.g value which we got 122.7 and 250.6 should take value from Corresponding column B i.e value of 50 and 100 )
Considering your Lookup value is in D1,
Put this formula in E1 to get upper range
=INDEX(B:B,MATCH(D1,A:A,1)+1)
and this formula in F1 to get the lower range
=INDEX(B:B,MATCH(D1,A:A,1))
This should work for you
c1 = Enter the search value
Formula in C2
=INDEX($A$2:$B$11,MATCH(INDEX($A$2:$A$11,MATCH(C1,$A$2:$A$11,1)),$A$2:$A$11,0),2)
Formula in D2
INDEX($A$2:$B$11,MATCH(INDEX($A$2:$A$11,MATCH(C1,$A$2:$A$11,1)+1),$A$2:$A$11,0),2)
Here is a sample of the data I have in one row in an excel file. I would like to split it into multiple rows after every seven columns
15-Feb 20 783 175 105 $180 $973 15-Mar 31 900 58 145 $106 $140
to
15-Feb 20 783 175 105 $180 $973
15-Mar 31 900 58 145 $106 $140
You can use this formula:
=INDEX($1:$1,INT(COLUMN()+(ROWS(A$5:A5)-1)*7))
drag/copy this formula across till row 7 and down as required.
Issue with this formula is it will return 0 if cell is blank.
So alternatively, you can check for cell blank condition and write formula as:
=IF(ISBLANK(INDEX($1:$1,INT(COLUMN()+(ROWS(A$5:A5)-1)*7))),"",INDEX($1:$1,INT(COLUMN()+(ROWS(A$5:A5)-1)*7)))
If you have a well defined and deterministic way to split the two halves (for instance, columns "A" to "D" is the first half, while columns "E" to "H" is the second), you can enter a formula in a different sheet like (this is pseudo-code; you will need to verify the syntax):
Cell "A1" of the new sheet: ='Other_Sheet'!A(round(row()/2)+1)
Cell "A2" of the new sheet: ='Other_Sheet'!E(round(row()/2)+1)
The indirect reference is made such that it will go to the next row in the source sheet every two rows in the new sheet.
I am trying to get value of sheet 1 cell "A19" in cell "A1" of sheet 2 and sheet 1 cell "A36" (which is 19+15) in cell "A2" of sheet 2. Do not want to use VBA as the number of rows in the sheets is high. have tried indirect function but havent been able to figure out how to reference cell from other workbook. is there any way this could be done?
In Sheet2, cell A1 enter:
=INDEX(Sheet1!A:A,19+(ROWS($1:1)-1)*17)
and copy down.
This will retrieve the data from these rows:
19
36
53
70
87
104
121
138
155
172
189
206
That is because the increment between 19 and 36 is 17.If you really want the increment to be 15, then substitute 15 in the top equation before the copy-down.
As you have said, you can also use INDIRECT , but INDIRECT is volatile so INDEX is a better choice
=INDIRECT("Sheet1!A"&1+(ROW()-1)*2)
I am trying to index match values from a long column to a grid of a different length. It looks like this
Word Number Column X Column Y Column Z
This 55 55 33 12
is 62 62 42 18
The 78 78 31 24
42
31
12
18
24
33
The grid (Column X,Y,Z) contains all the values from the Number Column. What I am trying to do is basically index the "Word" column, using a value from the "Number" Column, and looking it up in the value array of X Y Z.
Example (because this is confusing):
Input the Value 33 from the Number column, look for the value in the columns XYZ, and then return the Word "This".
Input the Value 18 from the number column, look for the value in columns XYZ, return the word "is"
etc...
Any help would be very much appreciated!
there is a quicker way and shorter formula to do this:
=IFERROR(INDEX(A:A,IFERROR(MATCH(B2,C:C,0),IFERROR(MATCH(B2,D:D,0),MATCH(B2,E:E,0))),1),"not found")
paste that into, any column really, into row 2 and drag down, it will return the words you require, if value not found it will return "not found"
Here is your spreadsheet starting at cell A1 (without your headers):
A B C D E
1 This 55 55 33 12
2 is 62 62 42 18
3 The 78 45 31 24
4 42
5 31
6 12
7 18
8 24
9 33
10
11 Input: 24
12 Output: The
Copy this into cell C10, and drag the formula across to cell E10:
=IF(ISERROR(IF(ISERROR(IF(ISERROR(MATCH($B$11,C1:C3,0)),"",CONCATENATE("A",MATCH($B$11,C1:C3,0)))),"",INDIRECT(IF(ISERROR(MATCH($B$11,C1:C3,0)),"",CONCATENATE("A",MATCH($B$11,C1:C3,0)))))),"",IF(ISERROR(IF(ISERROR(MATCH($B$11,C1:C3,0)),"",CONCATENATE("A",MATCH($B$11,C1:C3,0)))),"",INDIRECT(IF(ISERROR(MATCH($B$11,C1:C3,0)),"",CONCATENATE("A",MATCH($B$11,C1:C3,0))))))
Copy this to the "output" cell B12 and use cell B11 as your "input":
=CONCATENATE(C10,D10,E10)
VIOLA!!! You're done!
Proof:
The MATCH() function will look for your value in an array (the range). If it finds it, it returns the index of that array (indexed at 1), otherwise it throws an error. Be sure to set the 3rd argument to "0" so that it only looks for EXACT matches.
Paste this into C14:
=MATCH($B$11,C1:C3,0)
Next, we check if the MATCH() function did indeed throw an error. Paste this into C15:
=IF(ISERROR(C14),"",C14)
Now we have the row number of our matched value, so we will use the CONCATENATE() function to join it to our "word column", A, for use in the next step. Paste this into C16:
=CONCATENATE("A",C15)
Using that string from above, use the INDIRECT() function to turn it into an actual cell reference. Paste this into C17:
=INDIRECT(C16)
And finally, check if a legitimate cell reference was created. If so, return the word, otherwise return "". Paste this into C18:
=IF(ISERROR(C17),"",C17)
Lastly, drag the formulas from C14:C18 to E14:E18, and concatenate the results. The cells in row 18 should match the cells in row 10.
Hope this helps :)
Let's say I have the following table.
Team Score
AA 81
BB 67
CC 44
DD 1.5
JJ 279
LL 49
TT 201
GG 158
MM 32
HH 89
I want to get all teams that scored more than 80 in another table. I tried the Index + Match function as follows but it only gives me the smallest value greater than 80.
Here is the code:
=INDEX($A$2:$A$11,MATCH(80,$B$2:$B$11,-1))
Although I put the values in the lookup_array argument in descending order, this function only gives me one answer: The smallest value greater than 80.
I am trying to do this without having to sort the array and with a huge database mind you. Thank you.
Enter this formula to D2 and press CTRL+SHIFT+ENTER to make it an array formula, then drag it down.
=INDEX($A$1:$A$11,SMALL(IF($B$2:$B$11>=80,ROW($B$2:$B$11)),ROW(1:1)))
See How to look up a value in a list and return multiple corresponding values for details.
How about using an AutoFilter? You're then quite flexible in filtering for values in column score.
If you don't want to use vba, in a third column you could have
=if(B2 > 80, A2, "")
and copy that formula down. You could even put this column of formulas in another tab and either delete the rows that have nothing in them manually or write code that will do that for you.
Create a PivotTable (Team for ROWS, Score for Sigma VALUES, then filter the Sum of Score column for Number Filters, Greater Than..., and 80 next to Show rows where: is greater than *, OK.
* or perhaps is greater than or equal to.