How do I generate a new cell every time my function populates? - excel-formula

I'm trying to create a sheet that acts as a model stock market. I have code to randomly generate a positive or negative percentage to apply to a set(and later varying) principal. Every time I manually calculate my sheet, I need a new cell to generate with the latest balance(principal*random%) while still showing the previous balances. I've tried testing if the cell below is empty and then placing text in it, but once it reads the cell as no longer empty it becomes a circular reference. Ideal I'd like to be able to 1) calculate the new balance after applying the first percentage 2) save the new balance in its own cell 3) read that cell as the new balance while still viewing the initial value 4) repeat the function every time I calculate the page 5) create a graph and later algorithm plotting the points to resemble market trends.

You could use the Workbook_Change() event in VBA and write a short copy and paste script in there to store results of your calculation. You would probably want to combine this with a vba command for finding the last row in your results column to paste the new value.

Related

Creating a range that links to a closed spreadsheet

The databases that I use at work are created by a macro that automatically includes a couple of calculations beneath the data that calculate the change over the month and the annual change. This data gets updated on a monthly basis, so the cell reference where the calculations occur shifts downwards by 1 row per month (e.g. when we have data for March 2022 this would be added in row 15 and the monthly change calculation would shift down to row 17). The screenshot below is a rough example of the structure that the data is in (as I can't show you the actual data...)
I want to be able to create a range that finds the max/min of the values within the database without including any of the calculations (as some of these are likely to fall below the minimum value). This means that I can't just simply calculate the max/min for the entire column. For example, if I want to find the maximum of Var X, I can use the following equation to find the maximum within the range of B2:B14
=MAX(B$2:INDEX(B$2:B$1048576,MATCH(MAX($A$2:$A$1048576),$A$2:$A$1048576,0),)).
The problem is that using INDEX in this way causes the function to return #REF! if the database spreadsheet is closed when I open up the spreadsheet that this formula is saved in. Ideally I would like to find a function that can fulfil the same purpose without requiring the database spreadsheet to be open. Is anyone aware of a function that could be used to achieve the same result?
I have also tried a combination of INDIRECT and CONCAT, but this also returns the same #REF! error

How can I make a drop down list in Excel 2013 based on several conditions?

What I would like to achieve is that sellers can choose the STORE in the blue cell (either with a drop down list or by hard-typing the STORE name) and, based on the selection on the blue cell, the available POSITIONS for that particular PRODUCT and that particular STORE are show in the green cell as a drop down list.
Let's say I have an Excel workbook, which contains a worksheet with this table with products data, which is automatically imported daily from our Nav server with this layout. It has 4 columns including PRODUCT CODE, DESCRIPTION, STORE IN WHICH IT CAN BE LOCATED and POSITION INSIDE DE STORE (please, check screenshot). It contains 1.5k rows and it changes dynamically, for example, new items are added or positions are exchanged.
As you can see, the same product (PRODUCT 2) can be located in several stores (STORES 1, 2 and 3), and it can be in several locations on each store (POSITIONS 2, 3, 1 and 4).
Now I need sellers to report which of these items they pick and from where, not only the STORE but its POSITION inside the store too. They do it with another worksheet inside the same Excel workbook. It looks more or less like this (please, check screenshot).
I know the drop down list is achieved via Data Validation but I can't figure out the formula for this. I have tried several approaches like:
Array formula to return all POSITIONS in the same ROW, following this (Formula 2.): https://www.ablebits.com/office-addins-blog/2017/02/22/vlookup-multiple-values-excel/. It is quite slow to calculate on the 1.5k items and, once done, I can't figure out how to make Data Validation to look for the 4 or 5 or 10 POSITIONS returned by the array formula, which also need to be filtered by STORE (please, check screenshot for the closest that I have been, array formula returning POSITIONS from column E).
Same formula as above directly on the Data Validation list box, which returns only the first POSITION found.
VBA custom fucntions which are not allowed in the Data Validation box.
I feel comfortable with both Power Query and VBA, and forumla as well, and can adapt most of the code I see but I don't know why I just can't figure out how to achieve this, maybe it is only I am blocked or something but every path I start to follow ends up in a dead end.
Does anyone have an idea on how to approach this? It doesn't really seem that complicated but it is becoming impossible for me.
Thank you very much for your time!!
This is what I have finally done, just in case someone else is facing this situation.
Instead of a plain-text table for the POSITIONS, I created a PowerQuery importing that CSV. Named that worksheet _LOCATIONS.
Added a custom column (Column E) combining the PRODUCT and the STORE so I had something like a Unique Identificator, resulting something like this but in PowerQuery.
Combined column:
Sorted column E and sub-sorted column D, so I make sure the list will always be ordered as I need, and saved the query.
Then, in worksheet REPORT, I entered this formula to create the drop down list in Data Validation in cell D2:
OFFSET(_LOCATIONS!$D$1,MATCH($A2&"-"&$C2,_LOCATIONS!$E:$E,0)-1,0,COUNTIF(_LOCATIONS!$E:$E,$A2&"-"&$C2))
And I am able to choose from the available POSITIONS for the selected PRODUCT in the selected STORE.
Brief explanation:
I set the reference for the OFFSET function in the very first POSITION (D1), and then I move it the amount of rows detected by the MATCH function (which searches for the "PRODUCT 2-STORE 2" string in the newly created combined column) minus 1 (PoweryQuery table has headers) and 0 columns. This leaves me on the first occurrence of my string (but on the POSITIONS column). Then I make the offset as high as the amount of rows detected by the COUNTIF function (which counts all occurrences of my PRODUCT-STORE pair), returning an array of all the positions (column D) matching the PRODUCT-STORE pair.
Ask for formula in Spanish if you need it.

Excel Equivalent of a for loop

I have a link budget set up in an excel worksheet. The worksheet has one main input cell that the user can change to see how the data rate is affected. I want to make a plot that shows how the result cell (data rate) changes as the value in the input cell goes up. If I were working in python I would create a list of input values using range, loop over each value with a for loop to calculate the result, and append the resulting value to a new list. Then I would plot the results.
I haven't used excel for much in the past so I'm not sure how I would do this in my worksheet. Is there an Excel equivalent of the for loop sequence I mentioned above?

How do I stop excel updating cell references upon insertion of new data

I have a spreadsheet which takes in certain parameters that I update every day. This is then inserted into a separate worksheet which holds all inserted data. I then use this data to take an average of the latest 5 entries to smooth out day to day variation: e.g.
=((B1*(100-(AVERAGE(Data!G$2:G$6))))/(343.805764))
When I insert a new data line, my formula updates to:
=((B1*(100-(AVERAGE(Data!G$3:G$7))))/(343.805764))
How can I prevent this update?
If you really need to "fix" a range - regardless of the default behaviour of Excel to change row-numbers if you insert new rows - try working with hard-coded ranges using INDEX
=((B1*(100-(AVERAGE(INDEX(Data!G:G,2):INDEX(Data!G:G,6)))))/(343.805764))

Ignore cells on Excel line graph

I am trying to draw a line graph in Excel 2010. The y column data source has some gaps in it and I want these to be ignored for the graph. Seems to default these to zero. I know the "Hidden and Empty Cell Settings" exists, but this is only giving the option to set it to zero. Any other way to get my graph looking the way I want it
Image available once I have enough reputation!
if the data is the result of a formula, then it will never be empty (even if you set it to ""), as having a formula is not the same as an empty cell
There are 2 methods, depending on how static the data is.
The easiest fix is to clear the cells that return empty strings, but that means you will have to fix things if data changes
the other fix involves a little editing of the formula, so instead of setting it equal to "", you set it equal to NA().
For example, if you have =IF(A1=0,"",B1/A1), you would change that to =IF(A1=0,NA(),B1/A1).
This will create the gaps you desire, and will also reflect updates to the data so you don't have to keep fixing it every time
In Excel 2007 you have the option to show empty cells as gaps, zero or connect data points with a line (I assume it's similar for Excel 2010):
If none of these are optimal and you have a "chunk" of data points (or even single ones) missing, you can group-and-hide them, which will remove them from the chart.
Before hiding:
After hiding:
In the value or values you want to separate, enter the =NA() formula. This will appear that the value is skipped but the preceding and following data points will be joined by the series line.
Enter the data you want to skip in the same location as the original (row or column) but add it as a new series. Add the new series to your chart.
Format the new data point to match the original series format (color, shape, etc.). It will appear as though the data point was just skipped in the original series but will still show on your chart if you want to label it or add a callout.
There are many cases in which gaps are desired in a chart.
I am currently trying to make a plot of flow rate in a heating system vs. the time of day. I have data for two months. I want to plot only vs. the time of day from 00:00 to 23:59, which causes lines to be drawn between 23:59 and 00:01 of the next day which extend across the chart and disturb the otherwise regular daily variation.
Using the NA() formula (in German NV()) causes Excel to ignore the cells, but instead the previous and following points are simply connected, which has the same problem with lines across the chart.
The only solution I have been able to find is to delete the formulas from the cells which should create the gaps.
Using an IF formula with "" as its value for the gaps makes Excel interpret the X-values as string labels (shudder) for the chart instead of numbers (and makes me swear about the people who wrote that requirement).
Not for blanks in the middle of a range, but this works for a complex chart from a start date until infinity (ie no need to adjust the chart's data source each time informatiom is added), without showing any lines for dates that have not yet been entered. As you add dates and data to the spreadsheet, the chart expands. Without it, the chart has a brain hemorrhage.
So, to count a complex range of conditions over an extended period of time but only if the date of the events is not blank :
=IF($B6<>"",(COUNTIF($O6:$O6,Q$5)),"") returns “#N/A” if there is no date in column B.
In other words, "count apples or oranges or whatever in column O (as determined by what is in Q5) but only if column B (the dates) is not blank". By returning “#N/A”, the chart will skip the "blank" rows (blank as in a zero value or rather "#N/A").
From that table of returned values you can make a chart from a date in the past to infinity

Resources