Looking for an excel formula to autofill a column - excel-2016

I'm using a spreadsheet to assign box positions on shelves. The boxes are currently ranked by weight so that I can distribute that weight evenly across all shelves. As I'm assigning box positions, I would like excel to give me a running count for how many boxes have been assigned to each RACK and SHELF in the 'SHELF SPACE' column. A sample of the data is included below
What I'd like the SHELF SPACE column to do
I would like excel to find the previous SHELF SPACE for a given RACK and SHELF and add it to the BOX HEIGHT. The sum would then be the new SHELF SPACE value.
Entering by hand has taken a long time, so I've tried looking for formulas to help, but haven't had any luck piecing things together.
I've tried a lot of different formulas but the following has gotten me the closest.
what I've tried
I concatenated the 'RACK' and 'SHELF' columns, then I tried the following formula (which is in the image above):
INDEX(B2:B12,AGGREGATE(15,6,ROW(E2:E12)-1/(E2:E12="A4"),2))
I feel like this is getting me closer, but it can't give me a running count and only tracks box heights that match "A4" and the aggregate formula will only return a value if I input the K value.
UPDATE: 1/6/2023
I made the following formula, which gets me even closer, but this still only makes a running count for cells containing "A4". I would like it to make a running count for cells that also contain "B4" through "X4"
=IF(U2<>"A4","",SUMIF($U$2:U2,"A4",$P$2:P2))
UPDATE 1/6/2023
I made a nested if formula that seems to be doing what I want, but it is too long, so I've broken it in to 4 parts (1 string for each shelf). Here it is (from another spread sheet that I've been testing on). If it could be simplified, that would be great. I've also read that long nested IF statements can start producing errors.
IF(R2="A4",SUMIF($R$2:R2,"A4",$O$2:O2),IF(R2="B4",SUMIF($R$2:R2,"B4",$O$2:O2),IF(R2="C4",SUMIF($R$2:R2,"C4",$O$2:O2),IF(R2="D4",SUMIF($R$2:R2,"D4",$O$2:O2),IF(R2="E4",SUMIF($R$2:R2,"E4",$O$2:O2),IF(R2="F4",SUMIF($R$2:R2,"F4",$O$2:O2),IF(R2="G4",SUMIF($R$2:R2,"G4",$O$2:O2),IF(R2="H4",SUMIF($R$2:R2,"H4",$O$2:O2),IF(R2="I4",SUMIF($R$2:R2,"I4",$O$2:O2),IF(R2="J4",SUMIF($R$2:R2,"J4",$O$2:O2),IF(R2="K4",SUMIF($R$2:R2,"K4",$O$2:O2),IF(R2="L4",SUMIF($R$2:R2,"L4",$O$2:O2),IF(R2="M4",SUMIF($R$2:R2,"M4",$O$2:O2),IF(R2="N4",SUMIF($R$2:R2,"N4",$O$2:O2),IF(R2="O4",SUMIF($R$2:R2,"O4",$O$2:O2),IF(R2="P4",SUMIF($R$2:R2,"P4",$O$2:O2),IF(R2="Q4",SUMIF($R$2:R2,"Q4",$O$2:O2),IF(R2="R4",SUMIF($R$2:R2,"R4",$O$2:O2),IF(R2="S4",SUMIF($R$2:R2,"S4",$O$2:O2),IF(R2="T4",SUMIF($R$2:R2,"T4",$O$2:O2),IF(R2="U4",SUMIF($R$2:R2,"U4",$O$2:O2),IF(R2="V4",SUMIF($R$2:R2,"V4",$O$2:O2),IF(R2="W4",SUMIF($R$2:R2,"W4",$O$2:O2),IF(R2="X4",SUMIF($R$2:R2,"X4",$O$2:O2),"")))))))))))))))))))))))))))

Related

Select column and filter contents before searching on another worksheet

I´m trying to wirte a code and need some help.
I´ve managed to write parts of it using many sources around the web, but got to a point where I can´t find something to use as model or maybe find the right function.
I have an excel workbook with 2 worksheets, on the first one I have data from income and payments. With the code below I´ve managed to sort out the payments by eliminating blank cells from a range on "Plan1" and then copied to the other worsheet - "Plan2"
On Plan2 I get the following results:
Now, as you may see most of the codes are ending in "01".
What I need is:
After selecting column C; - done
Get all the values and search for them on Plan1, but removing the trailing "01" from them (since they vary in length) before search and then color the results on Plan1.
Advices please.
EDIT: I need to ignore the lines that do not end on "01". The full column will be selected.

Writing a VBA makro to sum a nested bill of materials

Hi I have looked around extensively on the web but have not been able to find a way to calculate a nested table of totals.
My data is pictured below.
What I am looking for is a way to add up all of the sub items of an item and put that total in the cost of the original item.
so for instance the total of line 6 will be the sum of lines 7,8,9, and 10. but the total of line 2 will be the totals of lines 5,6,11, and 12 each of which needs to be seperatly subtotalled.
I have tried excels subtotal function, but it is clumsy and not a generalised solution. I may need to add or subtract components over time and have the totals calculated again.
I have tried a few if then and for loop combinations, as well as an attempt at a function that calls itsself, with very limited success.
I think I have a block in how to approach this, as well as some programming knowledge gaps, like can a function call its self, and if it does, will it automatically create an independant set of function instance variables, or will the new call overwrite the old instances variables.
Any help with methodology and knowledge would be great.
Thanks
Does this formula work for you? In a new column, say E, starting in E3 and copied down:
=SUM(IF(LEFT(B3:B$999,LEN(B3))=B3,D3:D$999,0))
Here 999 is a dummy last row --- change it to suit your situation.
Columns B and D are assumed to hold Outline and Bom Cost, respectively. The logic is: sum up all rows below (and including) the current row if and only if Outline starts like the current row's Outline. So if Outline in the current row is 1.2.3 it sums up all Bom Costs found below where Outline start with 1.2.3 (1.2.3.1, 1.2.3.2, 1.2.3.2.1, etc.).
This formula assumes that the outline is properly ordered.
It is also assumed that the Outline values are text. If they are not, the formula above will fail when Outline is a whole number (1, 2, ...). This longer formula converts whole numbers to text and should work:
=SUM(IF(LEFT(B3:B$999,LEN(B3))=IF(LEN(SUBSTITUTE(B3,".",""))<LEN(B3),B3,TEXT(B3,"0")),D3:D$999,0))
Hope this helps.

How to randomly distribute a known group of numbers into a column using Excel / VBA

I'm stuck with excel/vba:
I've got a 10 row x 30 column blank array in Excel. I am trying to distribute 10 integers from a known group of 10 (say 1,1,1,1,1,1,3,5,7,9) into each column randomly so that each row of the column contains one of the group (and all of the group members are used once), and I need the second column to contain another random distribution of the same group and so on.
So I'd end up with 30 columns of 10 rows each, with each column containing a different random distribution of the same 10 integers. I want to be able to change the distribution in each row by recalculating the spreadsheet too.
Is there a quick way to do this? Short of arranging 30 different rand() sorted lists and using lookups I couldn't see a way. I'm not savvy enough with VBA to have a go. If someone can point me in the right direction, I'd be eternally grateful!
Perhaps I'm missing something obvious, though this does not seem to be so straightforward using worksheet formulas alone.
If your orginal list of values is in A1:A10, then, in B1:
=INDEX($A$1:$A$10,RANDBETWEEN(1,10))
and in B2, array formula**:
=INDEX($A$1:$A$10,INDEX(MODE.MULT(IF(COUNTIF($A$1:$A$10,$A$1:$A$10)-COUNTIF(B$1:B1,$A$1:$A$10),{1,1}*ROW($A$1:$A$10))),RANDBETWEEN(1,10-ROWS($1:1))))
Copy the above down to B10.
You can then copy the formulas in B1:B10 to the right as desired.
Regards
**Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).
You could make a loop in which you make an array with your 10 numbers. Then loop though 30 columns, with first adding another column of 10 randomly drawn numbers to your array. See this website on how to draw random numbers. Then sort the array on the second column and post the first column.
Edit:
As I read in the comments on the other answer, the purist solution would be to:
Assign each unique option of values a random value
Sort these random values either from top to bottom or bottom to top, and select the top one.
Place it in the first row
Do the same thing again for the second row, but keep track of the sum of all the unique options, as to rule out an option once it maxed its presence.
Edit2:
Once I just clicked post I thought this a bit more through and came to the conclusion that the last digit will allmost always be 1 in this case....

Count unique string variants

There could be quite a simple solution to this, but I am trying to find the number of times a unique variant (i.e. non-duplicates) of a string appears in a column. However this string is only part of the text contained in a cell, and not the entire cell. To illustrate:
EuropeSpainMadrid
EuropeSpainBarcelona
AsiaChinaShanghai
AsiaJapanTokyo
EuropeEnglandLondon
EuropeSpainMadrid
I would like to find how many unique instances there are of a string that contains "EuropeSpain". So using this example, I would find that a variant of "EuropeSpain" appears only twice (given that the second instance of "EuropeSpainMadrid" is a duplicate).
A solution to this is to use pivots to summarise the data and remove duplicated; however given that my underlying dataset changes often this would require manual adjustments and corrections. I would therefore like to avoid adding any intermediate steps (i.e. PivotTables, other data sets etc) between my data and the counts.
UPDATE: I now understand to use wildcards to solve the first part of my question (counting the occurrences of "EuropeSpain"), however I am not yet clear on the second part of my question (how to find the number of unique occurrences).
Is there a formula or VBA code that could do this?
Using wildcards:
=COUNTIF(A1:A6,"="&"*"&C1&"*")
For without VBA but with some versatility, I suggest with Text in ColumnA (labelled), ColumnB labelled Flag and EuropeSpain in C1:
=FIND(C$1,A2)
in B2 copied down.
Then pivot A:B with Flag for FILTERS (and 1 selected), Text for ROWS and Count of Text for Sigma VALUES.
Apply Distinct Values if required (and available!), alternatively a formula of the kind:
=MATCH("Grand Total",E:E)-4
would count uniques.

Excel - How do I find all relevant rows by typing unique invoice# listed Col A

I have a Worksheet with 10 columns and data range from A1:J55. Col A has the invoice # and rest of the columns have other demographic data. Goal is to type the invoice number on a cell and display all the rows matching the invoice number from col A.
Besides auto filter function, the only thing comes to my mind is VBA. Please advice what is the best way to get the data. Thanks for your help in advance.
Alright, I'm pretty proud of this one. Again avoiding VBA, this one uses the volatile formula OFFSET to keep moving its VLOOKUP search down the table until it's found all matches. Just make sure you paste enough rows of the formula that if there are many matches, there's room for all of them to appear. If you put a border around your match area then it would be clear if you ever ran out of room and needed to copy down the formula some more.
Again, in the main section, it's just a single formula (using index):
=IFERROR(INDEX($A$1:$J$200,$M3,MATCH(N$2,$A$1:$J$1,0)),"")
This gets to be so simple because the hard work of the lookup is done by an initial column which looks up the next row that matches the invoice number. It has the formula:
=IFERROR(MATCH($L$2,OFFSET($A$1:$A$200,M2,0),0)+M2," ")
Here is the working example that goes with those formulas:
Let me know if you need any further description of how it works, but it mostly uses the same rules as above so that it's robust in copying and moving around.
I've uploaded the Excel file so you can play with it, but everything you need to reproduce this feature should be in this solution.
Google Docs - Click link and hit Ctrl+S to download and open in Excel.
A popular solution to this problem is a simple VLookup. Lookup the invoice the user types in on the table A1:J55, and then return an adjascent column's data.
Here's an example of it working:
The formula in the highlighted cell is:
=VLOOKUP($L3,$A:$J,MATCH(N$2,$1:$1,0),FALSE)
What's nice about this formula is you only need to type it once and then you can copy it across and it'll automatically pick out the correct column of the table (that's the match part). The rest is very simple:
The first part says lookup value $L3 (the invoice number typed in),
The second part says look it up in range $A:$J (which is where your table is located). I've shown how you can select the entire columns $A:$J so that you can add and remove data without worrying about adjustin the range in your lookups. (Excel takes care of optimizing the formula so that unused cells aren't checked)
The third part picks the column from which the resulting data will be drawn once a matching row is found.
The FALSE part is an indication that the invoice number must match exactly (no approximate matching allowed)
The $ signs ensure that fixed ranges like the location of your source table ($A:$J) and your lookup value ($L3) don't get automatically changed as you copy the formula across for multiple columns.
The formula is pretty easy to adapt if you want to move around your table and the area where you do your lookup. Here's an example:
Bonus
If you want to add a little spiff, you can add a dropdown to the Invoice # field so that the user gets auto-completion and the option to browse existing values like so: