Dynamic data validated drop down list - excel

I am using VBA but I don’t mind using something else!
I have a table with 2 columns
Col A - Heading "RP" with 20 rows begining with "Rept Pd 1" down to "Rept Pd 20"
Col B - Heading "Claims Months", each cell a data vlidated list "0 Months" to "9 Months".
A seperate cell with "Total Months".
Background: Above table is to split reporting for a project into claims months. Maximum possible number of reporting periods (RP) is 20 and minimum is 1. Claims months can range from 0 Months to 9 Months. The total number of Months is hard keyed in, based on the figure in Total Months the ‘Claims Month’ cells for each ‘Rept Period’ should list in a drop down the number of possible Months.
E.g. If the Total Months were 24 and I were to select the Claims Months for ‘Rept Period 1’ to 20 months then ‘Rept Period 2’ should give me a list between 0 Months and 4 Months. If I selected 1 Month for 'Rept Pd 2' then drop down option for claims months for 'Rept Pd 3 should be 0 Months to 3 months and so on.
Hope that makes sense!
Many thanks

Byron is right that you should limit the selections to the numbers only. I'll add some extra steps for if you really want to have the " months" included, but this makes the whole thing even more difficult and space consuming.
What you will need to do is:
1) Assuming you have the Total Months value is in J1, and that the individual Claim Months are specified in Column I, add this formula =J1-SUM(I:I) to another cell in the same worksheet (I'll assume K1 is used). NOTE: The Total Months & the Claim Month selections should NOT be in the same column.
2) Fill enough rows of one column with this formula: =IF(ROW()-1<=K$1, ROW()-1, "") so that you cover the largest possible Total value. Ex. if you'll never have a Total Months>100, the formula should be in rows 1-100. I'll assume you use column L, so adjust accordingly.
3) In another, out-of-the-way cell add the formula =COUNT(L:L). I'll assume you use N1.
4) You now need to create a named range. To do that, go to the Formulas portion of the ribbon and click "Name Manager". In the window that opens, click "New". Add any name that suits your purposes (no spaces or special characters, except underscores), set "Scope" to the worksheet you're on, and in "Refers to:" enter this formula =OFFSET($L$1, 0, 0, $N$1, 1). Add a comment if you like, and then click "OK".
5) Highlight the rows that you want to use for the Claim Months values and open the Data Validation window. Select "List" in the "Allow" field, and in the "Source" field type = and hit F3. In the "Paste Name" window that appears select the Named Range we created and click "OK". Click "OK" in the Data Validation window as well.
Optional
6) Add this formula =IF(L1="", "", CONCATENATE(L1, " months)) to the column next to the one we added formulas to in Step 2. Drag that formula to cover the same rows we used in Step 2. I'll assume Column M is used for this formula
7) Adjust the formula in the Named Range we created in Step 4, so that $L$1 is replaced with $M$1
8) In another column (I'll use column H) add this formula =IF(I2="", "", VALUE(LEFT(I2, LEN(I2)-7))) and have this formula appear next to each Claim Month selection cell.
9) Update the formula from Step 1 to replace I:I with H:H
You should be set.

Related

Excel or VBA to subtract values on list with duplicate ID according to stock

I have list of IDs with warehouse stocks and list of shipments to customers which might have same ID.
Attached screen with example, so for 29.08.2022 with hour 08:00 we need to have 100 carrots, on warehouse we have 375pcs = 275pcs are left. Then few hours later we have shipment to other customer which requires 500pcs of carrots, 275-500 = -225pcs -> it shows info we need to harvest that much more untill 11:00.
needed vlookup for value from stock
then subtract every repeated value from top to bottom
carrots example screen
Looking for formula or vba which could handle this calculation without manual addition of many columns - currently I have something done with countif for as much as 10 duplicate ID - it just adds "1-"&ID then subtract this and takes it as "2-"&ID.. etc. It's very slow on performance.
As for VBA there is probably no possibility to dynamically declare ID from range as variable from stocks and then simply subtract in loop?
Something like this should work (paste in B2 and use autofill) :
=VLOOKUP($B2,$K$3:$L$17,2,FALSE)-SUMIF(INDIRECT("$B$2:$B$" & ROW()),$B2,INDIRECT("$C$2:$C$" & ROW()))
VLOOKUP($B2,$K$3:$L$17,2,FALSE) return the stock value of the item of the current row (777 for row 2)
SUMIF(INDIRECT("$B$2:$B$" & ROW()),$B2,INDIRECT("$C$2:$C$" & ROW())) return the sum of qty ship (of the current row and rows above) of the item of the current row (250 for row 2, 350 for row 5)
what about simple sumifs formula like below?
=L3-SUMIFS(C:C,A:A,J3)
place in cell M3 add drag/copy to the bottom

How to do addition and subtraction from different sheet and show result on another sheet in excel

I have three sheets Live, Buy and Sell, there I am maintaining Items. In Buy sheet I am tracking all buy items along with buy price & quantity similarly in sell sheet tracking sell orders. In Live sheet I want to see how many items are remaining.
Like if I purchased 200 XYZ item and sell 100 items so in Live sheet it should show 100 items against XYZ. One important point is I am adding entry in only two sheets Buy and Sell. I want Live sheet should automatically update.
In my current sheet I am using below formula for auto updating Live sheet but it has one disadvantage I can’t add multiple orders for same item. I am purchasing item in multiple order as shown in below screenshot.
=IF(ISBLANK(Buy!C3)," ",Buy!C:C)
Buy Sheet –
Sell Sheet –
Live sheet Should be like this –
I tired with some basic formulas like vlookup, if etc but that is not working.
Is there any formula/trick in excel to do such operations?
Below are software details -
I need answer which should be applicable for all version of excel after 2013.
Here is my sample file
https://drive.google.com/file/d/1CFJqTYi75eiUnEqUoHP2py9x7qphGpMHZ/view?usp=sharing
Please help, thank you for your help…!
This is a complete revision of my previous answer, which incorporates VikaS GuttE's comment.
Assumption
You can have an additional tab
The structure on "Buy", "Sell" and "Live" is fixed, e.g. starting with headlines in row 2.
Changes to previous approach
No additional columns needed on "Buy", "Sell" and "Live".
Reduction from 12 helper columns to 3. This can be further reduced to 2 if an item cannot be listed on the sell tab without being on the buy tab as well.
The Tabs
The Calc tab
Purpose: To retrieve a list of unique items.
The highlighted areas contain the following formulas:
"Buy" (blue): =IF(COUNTIF(Buy!B$3:B3,Buy!B3)=1,MAX(B$2:B2)+1)). It calculates how often the item on the same row but on the Buy tab has appeared until now. If it is the first occurance, it adds 1 to the max value so far. This way, I am getting a unique sequence for each unique item.
"Sell" (green): =IF(COUNTIF(buy_item,Sell!B3)>0,FALSE,IF(COUNTIF(Sell!B$3:B3,Sell!B3)=1,MAX(calc_buy)+MAX($C2:C2)+1)). It checks, if the item on the same row but on the Sell tab already occured on the Buy tab. In that case, the result is FALSE, otherwise it checks if this is the item's first occurance on the Sell tab. In that case, it takes the current max in this column so far, adds the max of the buy column and another 1, to continue the sequence started on the buy column. This way, each item gets a unique number, regardless if it is listed on buy, on sell or on both tabs.
"Unique" (orange): =IF(ROW()-2>MAX(calc_sell),"",IF(ISNA(INDEX(buy_item,MATCH(ROW()-2,calc_buy,0))),INDEX(sell_item,MATCH(ROW()-2,calc_sell,0)),INDEX(buy_item,MATCH(ROW()-2,calc_buy,0)))). It checks if the current row minus 2 (as the formula starts in row 3) is higher than the max value of the sell column. In that case, there are no more unique items and the cell stays empty. Otherwise, it checks if the current item can be found on the Buy tab. If not, the item is taken from the Sell tab.
The Live tab
The highlighted areas contain the following formulas:
"Item" (purple): =Calc!E3. This is just a reference to the current entry on the unique items list.
"Price" (red): =IF(B3="","",SUMIF(buy_item,B3,buy_price)-SUMIF(sell_item,B3,sell_price)). It checks whether there is a valid item in the same row. If yes, it sums up all buy prices for that item and subtracts all sell prices.
The Buy tab
The Sell tab
Named ranges
buy_item: =Buy!$B:$B
buy_price: =Buy!$C:$C
calc_buy: =Calc!$B:$B
calc_sell: =Calc!$C:$C
sell_item: =Sell!$B:$B
sell_price: =Sell!$C:$C
Formulas used
COUNTIF (Excel 2003+)
INDEX (Excel 2003+)
MATCH (Excel 2003+)
MAX (Excel 2003+)
ROW (Excel 2003+)
SUMIF (Excel 2003+)
IFNA (Excel 2013+)
In-depth explanation of formula
Calc tab, column "B" with headline Buy, blue area: =IF(COUNTIF(Buy!B$3:B3,Buy!B3)=1,MAX(B$2:B2)+1))
Lets break it down:
=IF(does_item_occur_for_first_time, next_unique_number)
does_item_occur_for_first_time = COUNTIF(Buy!B$3:B3,Buy!B3)=1
Buy!B$3:B3 this references the "Item" column on "Buy" tab. As the headline is located in row 2, I start with row 3. Important Please note the exact definition of the range. Only the row in the start part of the range definition (the term left of the colon) is fixed by the dollar sign in front of it. The row in the end part of the range (the part right of the colon) is not fixed. This way, the range grows with each row and it checks only the values so far.
'Buy!B3' takes the content of cell B3 on the "Buy" tab as criteria for the "COUNTIF" formula. Important All four tabs need to have the same structure, meaning that the headlines should start in the same row. In addition, the two columns "Item" and "Price" need to be in the same order and column on the three tabs "Buy", "Sell" and "Live". Maybe, it helps to think of these three tabs as different z-levels in a 3D-cube. The formula above is placed in cell B3 on the "Calc" tab and thus it checks for the content of cell B3 on the "Buy" tab.
Putting these pieces of "does_item_occur_for_first_time" together, it does what it says. It checks whether the item in the same cell but on the Buy tab occurs for the first time, meaning that there is no entry above that cell that already featured that given item.
next_unique_number = MAX(B$2:B2)+1). We look at the area above (see, only the row left of the colon is fixed ($) to determine the latest number. When there is no numerical value (e.g. empty cells or headline), then it assumes 0. All we have to do is add 1 to get the next number. Please note that the growing range is starting in row 2 as we want to determine the number for row 3.
Calc tab, column "C" with headline Sell, green area: =IF(COUNTIF(buy_item,Sell!B3)>0,FALSE,IF(COUNTIF(Sell!B$3:B3,Sell!B3)=1,MAX(calc_buy)+MAX($C2:C2)+1))
=IF(did_item_occur_on_buy_tab,FALSE,IF(does_item_occur_on_sell_tab_for_the_first_time,next_unique_number_overall))
did_item_occur_on_buy_tab = COUNTIF(buy_item,Sell!B3)>0
"COUNTIF" is used to determine if the current item in B3 on Sell(!) tab is already been listed on "Buy" tab. If that is the case, the result of this formula is "FALSE". Please note: This time we check the whole "Item" column on "Buy" tab.
does_item_occur_on_sell_tab_for_the_first_time = ´COUNTIF(Sell!B$3:B3,Sell!B3)=1´
This formula is similar to "does_item_occur_for_the_first_time" explained above. Please note that the column on Sell tab does not match the column of the formula's cell as the "Items" are located in column "B" which is already occupied on the "Calc" tab.
next_unique_number_overall = MAX(calc_buy)+MAX($C2:C2)+1
The second part (after the plus sign) is similar to "next_unique_number" explained above. The difference is the first part, as we do not want to start your sequence again with 1, but with the maximum number of the "buy" column.
Calc tab, column "E" with headline Unique, orange area: =IF(ROW()-2>MAX(calc_sell),"-",IF(ISNA(INDEX(buy_item,MATCH(ROW()-2,calc_buy,0))),INDEX(sell_item,MATCH(ROW()-2,calc_sell,0)),INDEX(buy_item,MATCH(ROW()-2,calc_buy,0))))
=IF(is_there_another_unique_item,"",IF(the_item_did_not_occur_on_buy_tab,get_item_from_sell_tab,get_item_from_buy_tab))
is_there_another_unique_item = ROW()-2>MAX(calc_sell). We check, whether the current row minus 2 (as the headline is located in row 2) is greater than then highest number of unique items. If that is the case, then we show nothing ("").
the_item_did_not_occur_on_buy_tab = ISNA(INDEX(buy_item,MATCH(ROW()-2,calc_buy,0))). MATCH(ROW()-2,calc_buy,0) looks in the "calc_buy" column for the number that equals the current row minus 2. The result is either "N/A" or the row with regard to the "calc_buy" range that features the respective item's name. Here, the term is wrapped into "ISNA" as I want to determine if the number (item's first occurance) belongs to the "buy" or "sell" tab. Important: all named ranges, here "buy_item" and "calc_buy" need to have the same start and end row. For the sake of convenience, I set all ranges to comprise the full column.
get_item_from_sell_tab = INDEX(sell_item,MATCH(ROW()-2,calc_sell,0)). The formula is the same as above without the "ISNA" wrapper. It picks the item's name from the sell tab.
get_item_from_buy_tab = INDEX(buy_item,MATCH(ROW()-2,calc_buy,0)). The same formula is used for a third time. Here, it picks the item's name from the buy tab.
Pitfalls and how to avoid them
Buy, Sell, Live and to a certain degree Calc need to have the same structure. Each tab's content has to start in the same cell (here B2). If you want to add or remove columns or rows, then you should select all tabs at once and conduct that operation. Do not forget to ungroup the tabs after you are done to.
Extend the formulas on Calc until they cover all your content on Buy and Sell, e.g. if buy features 100 rows and sell 150, then the formulas should also be included in 150 rows beneath the headline.
All named ranges need to cover the same rows with the same start and end row. Here, all named ranges cover the whole column. If you cannot work with names, you can substitute them buy their corresponding range definition (see above).
You could do it with one query like this:
=arrayformula(query({Buy!A2:B;Sell!A2:A,-Sell!B2:B},"select Col1,sum(Col2) where Col1 is not null group by Col1 label Col1 'Item',sum(Col2) 'Price' ",0))
The only way that I could find to do it is really cumbersome. Here it is - requires Excel 2019 or 365:
In cell A2 of Live, put this formula to derive all unique Items:
=LET( buys, Buy!A:B,
sales, Sell!A:B,
bMatrix, FILTER( buys,NOT( ISBLANK( INDEX( buys, , 1 ) ) )*(INDEX( buys, , 1 )<>"Item") ),
bItems, INDEX( bMatrix, , 1 ), rB, ROWS( bItems ),
sMatrix, FILTER( sales,NOT( ISBLANK( INDEX( sales, , 1 ) ) )*(INDEX( sales, , 1 )<>"Item") ),
sItems, INDEX( sMatrix, , 1 ), sB, ROWS( sItems ),
idx, MOD( SEQUENCE( rB + sB,,0 ), rB) + 1,
UNIQUE( IFERROR( INDEX( bItems, idx, 1 ), sItems ) )
)
In cell B2 of Live put in this formula:
=SUMIF( Buy!A:A, A2#, Buy!B:B ) - SUMIF( Sell!A:A, A2#, Sell!B:B )
Result looks like this:
This runs really slow because it is trying to discover the arrays from columns. If you use Excel Tables instead, it speeds up. I created tBuy and tSell and the formula in Live!A2 becomes:
=LET( buys, tBuy,
sales, tSell,
bItems, INDEX( tBuy, , 1 ), rB, ROWS( bItems ),
sItems, INDEX( tSell, , 1 ), sB, ROWS( sItems ),
idx, MOD( SEQUENCE( rB + sB,,0 ), rB) + 1,
UNIQUE( IFERROR( INDEX( bItems, idx, 1 ), sItems ) )
)
And in Live!B2 becomes:
=SUMIF( tBuy[Item], D2#, tBuy[Price] ) - SUMIF( tSell[Item], D2#, tSell[Price] )
Update: You can try this new approach ={UNIQUE(Buy!A:A), {"Price";ArrayFormula((SUMIF(Buy!A2:A, UNIQUE(Buy!A2:A), Buy!B2:B))-(SUMIF(Sell!A2:A, UNIQUE(Buy!A2:A), Sell!B2:B)))}}. I don't have Excel on my system so I can't check it in Excel. But since this one is not using Query it should work on Excel as well.
Previous answer:
Use this formula in A1 of the Live sheet:
=QUERY({QUERY(Buy!A1:B, "select A, B where A is not null", 1);QUERY(Sell!A2:B, "select A, -1*B where A is not null label -1*B ''", 0)}, "select Col1, sum(Col2) group by Col1 label sum(Col2) 'Price'", 1)
The assumption is that all the data (including headers) starts at A1 in the Buy and Sell sheets.

How to use COUNTIF on date range - only counting duplicates once

Currently. I have it set up when someone enters information in column E (Action Taken) then the whole row will turn yellow so it is easily seen that that item is being dealt with.
Another conditional format that I have set up is that once 5 working days pass on the date entered into column F (Date Actioned) then the row will turn red alerting the user to chase up the issue again.
Every week the user will contact more suppliers on the list regarding the listed product, and fill in their action taken and date actioned.
What I am looking to do is to add up all the suppliers contacted in one week (i.e. week 1 , 05.02.18 to 09.02.18) Which I know can be done by using the formula;
=COUNTIFS(F4:F18,">=5/2/18",F4:F18,"<=9/2/2018")
HOWEVER I only want to count each company once! So even though between the date 05.02.18 to 09.02.18, 8 actions were carried out, they only contacted 4 suppliers.
Is this possible? (FYI the screenshots attached are just a quick mock-up of the real document which contains thousands of products and more in-depth information).
If you don't mind adding a couple of working columns, the following is a possible solution:
Step 1
Set up two cells to contain the min and max dates for your range that you used in your formula =COUNTIFS(F4:F18,">=5/2/18",F4:F18,"<=9/2/2018"). This will allow you to up date things without having to recopy the formula each time. I used cells E1 and G1 for min and max date respectively.
Step 2
In a new column generate a list of supplier IDs that match your criteria. I arbitrarily chose column H. I placed the following formula in H4 and copied down:
=IF(AND(F4>=$E$1,F4<=$G$1),A4,"")
Step 3
In a new column generate a list of the count of the first time a supplier ID occurs from column H and do not count blank spaces. I arbitrarily chose column I. I placed the following formula in I4 and copied down:
=--(AND(COUNTIF($H$4:H4,H4)=1,H4<>""))
Step 4
Take the sum of the results from step 3. I arbitrarily chose to place the following formula in I19:
=SUM(I4:I18)
The "cop out" route, if you were only doing the calculation for 1 week would be to have a Pivot Table, with the Company as the Rows and the Date as the Columns. Then filter your columns, and you get a row per Company that week.
The Full route means looking into Array Formulae - you type one of these like normal, but instead of pressing [Enter], you press [Ctrl]+[Shift]+[Enter], and the equation will show in curly braces. (This is why they are sometimes called "CSE Formula" for "Control, Shift, Enter")
~Warning - This is a long walk through how I calculated the final formula. Hopefully it will make sense though!~
An array formula lets you iterate through every row in a range, calculate them seperately, and then add them all together at the end. This gives us the outside term - everything goes inside a =SUM(..). Press [Ctrl]+[Shift]+[Enter], and this will display as {=SUM(..)}
Now, what calculation do we want to be doing per row? Well, for every row where column F is within date, you want 1 per company within date. Well, another was to say "per" is "divided by" (hence the "Percentage" symbol being "0 / 0" or "%", and the lesser knows "Permille" symbol being "0 / 00" or "‰")
For the sake of reproducibility, I am going to assume that your Count is being done in Cell J2, and you have the Start/End of week dates in Cells H2 and I2
The formula for Row 4 would start out as =IF(AND(F4>=$H2,F4<=$I2), 1/???, 0), where ??? is how many times the Company on row 4 appears. Unfortunately, the AND function does not work with Array Formula. Fortunately there is an easy workaround - since boolean True/False can be treated as binary 1/0, the AND operator is the same as multiplication. Converting from boolean to binary is fastest by double-negation, so AND(F4>=H2,F4<=I2) can be rewritten as --(F4>=H2)*--(F4<=I2), which will work fine with array formula, giving us =IF(--(F4>=H2)*--(F4<=I2), 1/???, 0)
Now, before we work out what ??? should be, I'm going to skip down to row 18. There is method to this madness, I promise! Following the rules laid out above, the formula for row 18 is =IF(--(F18>=H2)*--(F18<=I2), 1/???, 0) - fairly simple? Now, if we want to run this for all rows from 4 to 18, we just need to join the ranges. So, you would get =IF(--(F4:F18>=H2)*--(F4:F18<=I2), 1/???, 0) Turning this into an Array Formula would get you an array of "1/???"s and "0"s, so add it together with SUM to get a single 'flat' number: =SUM(IF(--(F4:F18>=H2)*--(F4:F18<=I2), 1/???, 0))
Remember that "method" I mentioned earlier? Well, if we were looking for a straight Count of actions taken, ignoring the Unique Companies constraint, we could make ??? = 1, to get =SUM(IF(--(F4:F18>=$H2)*--(F4:F18<=$I2), 1, 0)) and hit [Ctrl]+[Shift]+[Enter] - which would give the same result as =COUNTIF(F4:F18, ">="&H2, F4:F18, "<="&I2) - and changing the 1 to D4:D18 would be a SUMIF on Products. (Incidentally, you can remove the IF statement from the CountIf, since the Condition returns 1 or 0 already)
So, last step! What is ??? Well, it's a Count of rows where Date Actioned is within our date bounds, and Company is the same as the current row. So, for Row 4 you have COUNTIFS(B4:B18, B4, F4:F18, ">="&H2, F4:F18, "<="&I2), and for Row 18 you get COUNTIFS(B4:B18, B18, F4:F18, ">="&H2, F4:F18, "<="&I2), making the final ??? become COUNTIFS(B4:B18, B4:B18, F4:F18, ">="&H2, F4:F18, "<="&I2) (The trick here is that the Range arguments are treated as all the cells at once, but the Condition arguments are treated as an array of each cell one-at-a-time)
Now, some people might argue that you need to put your 1/COUNTIFS(B4:B18, B4:B18, F4:F18, ">="&H2, F4:F18, "<="&I2) inside an IFERROR to be safe - however, this is in the TRUE part of an IF statement referrring to the same row, so we know that if the COUNTIF is being evaluated then there will always be at least 1 row that matches.
So, if we stick it all together, and add a load of $ symbols to lock the rows/columns in place (so that you can drag down column J to calculate for different weeks/dates in columns H and I) you get the (slightly unwieldy) formula as follows:
=SUM(IF(--($F$4:$F$18>=$H2)*--($F$4:$F$18<=$I2), 1/COUNTIFS($B$4:$B$18, $B$4:$B$18, $F$4:$F$18, ">=" & $H2, $F$4:$F$18, "<=" & $I2), 0))
And, one last time - Don't forget to press [Ctrl]+[Shift]+[Enter]
(The 2 Date cells, $H2 and $I2 are the only terms I have left 'unlocked', and even then only on the Row)

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 - vertical look up list (without VBA)

I would like to find a formula that gives me a list of cells that contains a certain date.
Example:
name - day - amount - month (hidden)
a 01-01-2012 5 =month(01-01-2012) = 1
b 02-01-2012 4 =month(02-01-2012) = 1
c 10-01-2012 3 =month(10-01-2012) = 1
d 10-01-2012 6 =month(10-01-2012) = 1
e 11-02-2012 2 =month(11-02-2012) = 2
So in this example, I would like to get all the (unique) days of January (in my case a list with: 01-01-2012, 02-10-2012 & 10-01-2012).
Afterwards I would like to have the total of amounts on these days of the list above (but that's easy and I guess I will find that alone :p)
I first used the Vertical Lookup formula but this gives me only one day in January, and not a list of all the days in January.
In fact it's a filter that I need, but with a formula
Thanks for your time & help
For getting the list vertically:
Formula in column H of your sheet (array formula, insert with Ctrl-Shift-Enter, curled brackets inserted by Excel, not by user):
{=INDEX($B$2:$B$10;MATCH(0;COUNTIF($H$1:H1;$B$2:$B$10);0))}
Cells should be formatted as Date to get dates, not integers.
Horizontally:
{=INDEX(Data!$B$2:$B$10;MATCH(0;COUNTIF($A6:A6;Data!$B$2:$B$10);0))}
To filter out unique days in October:
=INDEX(Data!$B$2:$B$10;MATCH(0;IF(COUNTIF(A4:$A4;Data!$B$2:$B$10)=0;IF(MONTH(Data!$B$2:$B$10)=10;0;1);1);0))
Your sheet modified: http://www.bumpclub.ee/~jyri_r/Excel/filter_formula_month.xls
Select the cell you want the result to start appearing in.
Choose the Data ribbon and under filter you will find advanced
Choose the dates you want filtered, and at the bottom of that dialogue you'll find a checkbox with Unique Items only, check that one.
And Bob's youre uncle

Resources