SUMIF, VLOOKUP and SUMPRODUCT formula - excel

So I have this following spreadsheet.
Shipping WS
Col B is part number, Col C Where to ship. Col J is how many full skid and Col L how many more boxes to be added to full skip. There is a second sheet with the parts details like qty/box, box/skid, skid weight, etc...
Because everyday the is different, the number of lines in the first sheet will be different.
What I would like is a single cell at the top of the sheet that will give me total boxes going to each location that we ship to. So I want the sum of boxes for every lines that have NEWB as it destination as well as SANF. So each line calculation would be Value in K (number of full skid) * VLOOKUP of the part to get the box per skid (box per skid) + Value in L (number of loose boxes not making a full skid).
Is there a function that will do all of that for NEWB in one cell and SANF on another? The user enters the line as he goes so they are not all in groups. I might get 3 line of SANF then 2 of NEWB, then a couple of SANF and so forth.
Thanks,
Denis

I figured a way to do what I needed this weekend.
=SUMPRODUCT(K7:K52,IF(D7:D52="NEWB",1,0)*VLOOKUP(B7:B52,'Parts Data'!C3:H39,4,FALSE))
Basically I do a multiplication on every row no matter what with the sumproduct command. Number of skid (Col K) times the result of the IF statement. The IF statement will return the product of 1 times the vlookup value if the right location in Col D is what my formula is calculated for (NEWB) so basically the value of the vlookup is multiplied but number of skid for the sum. If the location is "SANF" then the product of the if command will be 0 times the value of vlookup which will give me 0, then time the number of skids, which will be 0 used for the sum.
I will copy and paste the same formula into a new cell and change "NEWB" to "SANF" in the formula for the calculation for the second location.
Hope this will help someone later.
Denis

Related

how to make IF conditions in SUMIF automatically extend to more columns?

Hi everyone I have the following excel table:
my task (performed in the green cell) is that for each year I compute the sum of the rows that contain a negative number in at least one of the previous years.
For instance the -1.29 in year two is the sum of the values in year to corresponding to rows 1,5,6,10,12 which are the rows containing negative numbers in the previous year. For year 3 same logic except that now I can sum all the values for that year from rows containing negative values either in Year 1 or Year 2.
for now in each of the green cells I am using the following formulas:
Year1 : 0
Year2 : =SUM(IF(B3:B13="-";0;B3:B13)($A$3:$A$13<0))
Year3 : =SUM(IF(C3:C13="-";0;C3:C13)((($B$3:$B$13<0)+($A$3:$A$13<0))>0))
Year4 : =SUM(IF(D3:D13="-";0;D3:D13)*((($C$3:$C$13<0)+($B$3:$B$13<0)+($A$3:$A$13<0))>0))
but I would like to make recursive, in the sense that I can just drag it to the next year without having to add one more of this ($C$3:$C$13<0) terms
would that be possible by just using Excel Formulas (hence no VBA)? An excel function computing the product of two vectors element by element would be enough but I cannot find anything like that unfortunately.
Hope to find some help!
Best,
Federico
Use MMULT:
=SUM(B2:B13*(MMULT(--($A$2:A13<0);TRANSPOSE(COLUMN($A$1:A1))^0)>0))
add formula to B14 and copy to the right. This is array formula.
If I understand you correctly, the following does what you want.
{=SUM(IF(A$1:A$13<0,B$1:B$13))}
Notes:
o The formula as shown is as it would be entered at B14
o Note the {}: This is an array formal so use Ctrl, Shift and Enter to enter the first case
o You don't need to eliminate text values (SUM does that automatically)
o I prefer to include headings (if they exist and are text) as it makes growing the table easier
Not sure why, but your example formulas started at row 3 (excluding row 2).
If that is truly what's wanted amend the above to:
{=SUM(IF(A$3:A$13<0,B$3:B$13))}
There is a quite simple solution in VBA:
Function getSum(rng As Range) As Variant
Dim r As Long, c As Long
For r = 1 To rng.Rows.Count
For c = 1 To rng.Columns.Count - 1
If rng.Cells(r, c) < 0 Then
getSum = getSum + rng.Cells(r, rng.Columns.Count)
Exit For
End If
Next
Next
End Function
Where the range passed to the function is written with a combination static/dynamic definition so the range expands. The upper left cell of the range will be the first cell of your data, static: say $A$3, and the lower right corner will be the bottom cell of the column with the values you are wanting to sum and dynamic, say: B14. In that case the formula =getSum($A$3:B14) would go in B15 and could be dragged over. Here's a picture:
I originally answered a different question than was asked. Currently editing to address the asked question using formulas only.

Incrementing a Cell in Excel which is associated with different columns and formulas and I wish to record the results of each increment carried out

I am looking to find a solution for the following:
I am trying to obtain the maximum revenue that can be earned by incrementing a cell in this sprenter image description hereeadsheet below, recording the results obtained from each increment and simply finding the maximum value of the list of recorded values from incrementing.
I am focusing on the cell J4 (Rev if New floor set) which contains the following formula [=SUMIF(B4:B24,">"&I4,H4:H24)] which computes a sum of the values in the column ‘Seller receives after Rev Share if floor increased’ that correspond to the rows where ‘Buyer_Bid > Minimum to be paid by Buyer’.
The Cell ‘Minimum to be paid by Buyer’(&I4) contains the formula [=F4/0.84] where the column F contains the Floor_Price. to be set (What I want to increment to find maximum solution (Overall Revenue).
The Cells in the column ‘Seller receives after Rev Share if floor increased’ contain the following formula ‘[=IF(E4>F4,E4,G4)] which places in the instance where the rows in column E ( Seller receives after Rev share) > rows in column F (New_Floorprice) the corresponding rows where this statement is true from column E and places them in Column H and for the instance that this condition fails it puts the corresponding to the rows failing the condition from Column G into H.
The Cells in the column ‘Buyer_Bid’ simply contain values which were imported and not created within the spreadsheet.
The columns which make up the final figure ‘Rev if new floor set’ depend on the New_Floorprice which I want to increment to find out which floor price results in the most revenue(Overall Revenue = Rev if New Floor Set – Rev Today)
I was hoping to be able to automatically increment Cell B1 by increments of 0.001 which then would change all the corresponding values in the spreadsheet as I have the Column F = B1 and then record the results for ‘Rev if New Floor Set’, ‘Rev Today’ and ‘Overall Rev’ for each increment carried out so I can simply obtain the optimal Floor price that produces maximum revenue. However 'Rev Today' solution will stay constant as the column that the formula is made up of was imported and left as is.
I have tried using solver for this problem by setting the objective to column L4 and choosing to maximise changing the variable cell B1 with the constraint of L4>=0 however kept getting a different result when I manually changed to optimal floor price B1.
I am trying to make this as clear as possible but please let me know if it is hard to understand. Also I have never used VBA so a solution which doesn't involve VBA would be great please. I have a link to an image of the spreadsheet below.
It would be much appreciated if I Could get some help with this please.
Many thanks,

Sum every 11 rows excel

I have a table with 2600+ rows, related to towns in my region and their population; each town has 11 rows, one for each age class (0-9, 10-19, and so on).
I need to get the sum of the population of each town; of course I can do it manually but it's a never ending job; I wonder if there's some kind of command that tells excel to do the sum every 11 rows and do it for all the towns.
I think it's a kind of loop but I have no idea about how to do it.
The problem can be reduced by using the SUMIF function. The question then becomes how to apply this to your dataset.
Assuming one of the columns in your 2600+ rows contains the town name (or another unique identifier), and you have a list of towns (or other unique identifier), the below method can be used.
The formula in E2 is =SUMIF(A:A,D2,C:C), and in E3 =SUMIF(A:A,D3,C:C). A to C is the list of all data, D is a list of towns.
For a VBA solution, you should be able to use a step in the loop.
So if you wish to step by 11 rows at a time.
Public Sub IterateRows()
Dim rData As Range, rPtr As Range
Dim dSum As Double
Dim i As long
Set rData = Sheet1.Range("A1:A1000")
For i = 1 To rData.Rows.Count Step 11
Set rPtr = rData(1).Resize(11).Offset(i - 1)
dSum = Application.WorksheetFunction.Sum(rPtr)
Next
End Sub
If you want a worksheet function solution, you will probably have to use the MOD operator and check for when the value is zero..
You can also try this manual method which is not a never ending job; i.e.:
in E11 put your formula as =SUM(C1:C11)
copy range E1:E11
select range E12:E2600 and paste special function
Do you have any reference columns? As in...say for example Column A has the Town Name, and Column B has the Age Class, and Column C has the values.
Going down the rows Column A will have repeating town names, yes?
Like this:
Town - Age Class - Pop
Wherever - 0-9 - 1000
Wherever - 10-19 - 2000
Wheverer - 20-29 - 2500
Assuming you have maintained the data structure (NO GAPS) a possible solution in Column D (or whatever column just make sure you change the references) could be (putting this in D2 and dragging it down the length of your sheet):
=IF(A1<>A2,SUM(INDIRECT("C"&ROW(A2)&":C"&SUMPRODUCT(MAX((A:A=A2)*(ROW(A:A)))))),D1)
This works if you have any amount of rows per town, so long as you SORT by town name so the same names are next to each other in the list and there are no gaps.
In the above test data set I subtracted 250 from each Values count per Town going down (each class has 250 less than the previous city) just to show some variation in the output...you can see each city has 2750 (250 * 11) less pop than the previous.
Basically it builds an array with a starting position of "not the town above" in the first row it encounters a new town name to an ending position of "last (max) position of new town in same list" so that is how it doesn't matter how many rows you have per town. From 1 to memory limit basically, I think. :)
ALTHOUGH, this also works:
=SUMIF(A:A,A2,C:C)
Yep. Not kidding just drag that down Column D...
Assuming the following structure
This is a very easy task using a pivot table.
For LibreOffice Calc:
Just select the complete data area including the column headers (in my example: A1:C13);
Menu Data -> Pivot Table;
Current selection;
Following settings for Pivot table:
(drag the Town field into the Row Fiels area, and the Count field into the Data fields area. LO Calc will offer to calculate the Sum of the count entries by default).
Hit OK - the resulting pivot table will look like this:
This solution has the advantage that the source data area hasn't to be sorted by town, and it doesn't matter if some towns don't have nine value rows each. Additionally, you don't need any formulas.
EDIT:
You can work with the contents of the pivot table the same way as with calculated results. For example, you could use the pivot table values to calculate the sum for some of the towns (in my example, calculate the sum for town B and C based on the pivot table values B3 and B4 respectively):
You could do this with the MOD function, which gives the remainder of division. You could look at each row number and if its MOD of 11 equals zero, then it's the row you're looking for.
I am counting 10 items in each section in your example so I'm not sure I completely understand. Let's assume you need to sum every row that ends in a 9 (A9, A19, A29, etc.). You can replace the 9's below with an 11.
=ROW(A9) gets you the row number.
=MOD(ROW(A9),9) gets you a TRUE or false on weather that number is divisible by 9. If it is a multiple of 9, it will return the number 0.
Now use the SUM function and hit CONTROL+SHIFT+ENTER to complete it. Note that the formula bar indicates that this is an array function by using curly braces. You don't need to type those in yourself.
{=SUM(A1:A9*(MOD(ROW(A1:A9),9)=0))}

Looking for formula to extract specific values from a row containing numbers and blanks

I have a sheet with rows of data, with many columns. I am looking for help on a formula that will extract the sum of the smallest 3 numbers in a row based on the last 5 values entered. Note that not all the rows will have values for each column, so the first value found on each row will may be found in a different column.
To determine the sum of the smallest 3 I am using the formula =SUM(SMALL(B3:R3,{1,2,3})), Unfortunately, that formula is looking at the entire range. Again, I am looking for help that with a formula that will select only the last 5 values posted.
Here is simple example. The results for each line show the totals that should be determined. Again, it needs to look for the sum of the smallest 3 based on the last 5 posted (in the example below the range would be col. 1 thru 10, with col 10 having the latest postings).
Ex.
1.....2.....3......4......5.....6.....7.....8......9.....10...... Result
31.........44....51....36..........44...34....36....38.......106 (34+36+34)
35..31...44...40.....38...52..........42....37...............115 (37+38+40)
Hope this is understandable. I am looking for a formula solution vs a VBA macro solution because of my users. Thanks for any help!!
Now that you clarified the question, I have an answer for you. This is fairly ugly but it gets the job done. You might want to hide the columns with the intermediate results - or you could get adventurous and "nest" the expressions. This makes it really hard to understand / debug though. If there's a smarter way to do this I am always open to learning.
Assuming you have the data in columns A through J, starting in row 2, put the following in cell L2:P2:
=MATCH(9999, A2:J2,1)
=MATCH(9999,OFFSET($A2,0,0, 1, L2-1)) ... copy this by dragging right to the next 2 columns
=MATCH(9999,OFFSET($A2,0,0, 1, M2-1))
=MATCH(9999,OFFSET($A2,0,0, 1, N2-1))
=MATCH(9999,OFFSET($A2,0,0, 1, O2-1))
The first line finds the last cell with data in it; the next ones find the last cell "not including the last cell", and so they work backwards. The result is a number corresponding to the columns with data. For your example, this gives
10 9 8 7 5
9 8 6 5 4
Now we want to find the sum of the smallest 3 of these: put the following equation in cell Q2:
=SUM(SMALL(INDIRECT("RC["&P2-17&"]:RC["&L2-17&"]",FALSE),{1,2,3}))
Working from the inside out:
RC["&P2-17"] results in RC[-12], which is "the cell 12 to the left of this one".
That is the first of the "last five cells with data", cell E2
RC["&L2-17"] results in RC[-7], the last cell with data in this row
FALSE use "RC" rather than "A1" indexing
INDIRECT turn string into an address (in this case a range)
SMALL find the 3 smallest values in this range
SUM and add them together.
This formula did indeed give me 106, 115 for the example you provided.
I would hide columns L through P so you only see the result (and not the intermediate stuff).

Excel - Wrap range of rows at a given column, with first column repeating for the range of rows

Technically, the solution I'm looking for is to minimize actual programing. I need to know if there is Excel functionality I can invoke from VBA, instead of having to code the entire logic myself.
Imagine the following sheet:
Position Competency1 Competency2 Competency3 Competency4
Employee1 x x
Employee2 x x
What I need is the following result:
Position Competency1 Competency2
Employee1 x
Employee2 x
Position Competency3 Competency4
Employee1 x
Employee2 x
In other words, I want Excel to move the columns down, but maintain the first column. Now for the complicated bit; there will be several positions, with various employees. So a final product might look like:
Position Competency1 Competency2
Employee1 x
Employee2 x
Position Competency3 Competency4
Employee1 x
Employee2 x
Position2 Competency5
Employee3 x
Employee4
The data is fetched from a database and formatted into the above layout via VBA. The amount of positions and employees/competencies per position are all variable.
I can of course code the entire thing, but it would make my life a lot easier if I could just throw some parameters at Excel and have it do it for me. Problem is, what relevant functionality I've found appears to be sheet-wide, while I need to be able to specify multiple sets of rows and columns.
I rather suspect the answer is: "Suck it up and code it". But I don't know enough Excel to say for sure.
I'm assuming the first list will be Position with Employees down the bottom. And that no other lists are there. Assuming this: here is logically what you need to code
numberOfColumns: Count the cells going down where the cell is not blank in column A (the position column) minus 1. This will give the number of employees (excluding the Position cell).
numberOfRows: Count the number of cells going across (row 1). This will be the number of Competency cells minus 1 (excluding the Position cell).
competancyColumns : Define a variable capturing how many competency columns they need for each position. This can be through a textbox or in a cell on another sheet or something e.g. a value of 2
Start at A1 + competancyColumns. Copy and cut cells after to end of row.
Start at A1 + numberOfRows + 1. Add another counter to keep track of position (counter) so after point 4 the counter should read 2 (0 + competancyColumns).
Paste cells (from point 4)
Repeat process until the counter = numberOfcolumns. Obviously not starting at A1 but the row you were at.
You can store it in an Array if you don't want to use Cut and Paste, but thats for you to decide.
SO that should be the basic logic.

Resources