Controlling calculation procedure in Excel - excel

I have a specific question concerning the calculation procedure in Excel. Thing is, I have a couple of rather "slow" functions that I have implemented myself in VBA. Everytime I open the specific workbook, or only make a small change in a worksheet, everything have to calculate and thus, take a very long time (annoying).
I wonder if there is a way, other than just checking "manual calculation" under "options/formulas", to control certain (self-implemented) VBA-functions to calculate ONLY on demand (with press of a button for instance)? The most optimal solution would be to be able to have all other formulas to be calculated automatically, and the remaining VBA formulas only calculated when needed.
Thanks,
N

You could have a control cell that links to your VBA functions.
If cell A1 = 1 fire script, else end.
Then when you want it to calculate make it a 1, else a 0?
You could do it with a tick box to make in slightly more elegant. :)

Related

Change a cell value permanently in Excel

I prepared an Excel worksheet to monitor my trades on Binance crypto market. I created a simple formula to make one cell's value (A12 for example) change to "done" when the coin's value is equal to sell price. (pretty easy). However, this changes when the coin's price becomes less than sell price!
Is there any way to make the word "done" permeant when the condition is met?
Thank you guys.
You could experiment with circular references. Check the "enable iterative calculation" option in the formula tab of the Excel options under the File menu. Then, as proof of concept, in A12 enter the formula:
=IF(A12="done","done",IF(A11>5,"done","undone"))
This will switch to "done" the first time the value exceeds 5 but won't switch back to "undone" if the value later drops below.
On the other hand, circular references make the worksheet harder to reason about. A VBA solution will probably be more robust.

Will it be more efficient referencing a cell containing a volatile function than including the function in several formulas?

When e.g. searching for the current month in a table, is it better to use a TODAY() function in a single cell to calculate the month, or is it just as efficient putting TODAY() in every formula which uses the current month.
The reason I'm asking is that while answering a question earlier today, I recommended putting the current month (calculated based on TODAY()) into a single cell and reference this, instead of including it in every formula in the sheet. However, upon reading the documentation on volatile functions, I came across the text
Excel reevaluates cells that contain volatile functions, together with all dependents, every time that it recalculates.
Since all dependents are reevaluated anyway, does it matter whether TODAY() is in another cell or in the dependent formula?
I ran a little experiment, because I've always wondered this too.
I created a spreadsheet with 200,000 x 100 cells with =TODAY() inside them.
From VBA, I executed Application.CalculateFullRebuild, and then Application.Calculate
Interestingly, Excel was very slow grinding through that second calculate instruction, even though the dependency tree had been fully rebuilt.
I ran a second experiment, this time populating every cell with =NOW(), and I repeated the process.
The results were even more surprising!
Firstly, the first and last cells had different values
Then I changed the format to ss, so I would only see the seconds component.
Each cell had a different result! Excel did not appear to be solving each instance of =NOW() by working left-right and top-down, but appeared to be solving some other way.
Picture of Calculation Experiment: Top-left corner
Picture of Calculation Experiment: Bottom-right corner
While the cells tended to have a similar (but not the same) answer when they were close together, the further two cells were apart, the more different their results were!
"Common sense" would suggest that Excel would only solve volatile functions once per Calculate() command, grouped by inputs, but this is not the case. Instead, every single call to a volatile command has it recalculated afresh.

Excel SUM COUNTIFS from different tables and futureproofing

I'm practising MS Excel skills. I have a workbook in which I want to analyses data from different tables.
Each worksheet contains a table with the information from the year. So in worksheet "2017" I have a table named "Table2017". I have this for each year (starting 2015).
After a some research, I finally found a way to count how many times something in a certain place happened.
=SUM(COUNTIFS(Table2018[Place];B3;Table2018[Activity];{"Paid";"Awarded"}))
+SUM(COUNTIFS(Table2017[Place];B3;Table2017[Activity];{"Paid";"Awarded"}))
+SUM(COUNTIFS(Table2016[Place];B3;Table2016[Activity];{"Paid";"Awarded"}))
+SUM(COUNTIFS(Table2015[Place];B3;Table2015[Activity];{"Paid";"Awarded"}))
This works perfectly. It will calculate how many times per place a paid service or an awarded (gifted/sponsored) service was delivered. In the B column, I have a list of places (hence the B3 reference), so after completing the formula, I can select the cell and enlarge/drag to copy it to the rest of the column and apply for every place.
However, the formula is really long and every year upon creating a new worksheet, I need to add a new part to the formula.
Is there a way to compact this? And ideally have the formula search for every table that has the relevant information (like: "Table20??" or "Table 20*"), go in and count the times my conditions are found?
I hope my question is clear enough.
Thanks in advance!
P.S. I have zero experience in VBA/VBS, so I'm hoping to realize this in a normal formula.
There are ways to make it more compact, but they will necessarily make the function more complicated, so it wont be any easy win. See for yourself:
you basically need to be able to cycle through the years inside formula without creating custom formulas. One way to do this is to use ROW inside INDIRECT function. This way you can replace multiple
Table2015[Place]
with one array function containing
INDIRECT("Table"&ROW($A$2015:$A$2018)&"[Place]")
as it is an array function it will essentially cycle through the cells in the ROW function creating Table2015[Place], Table2016[Place], Table2017[Place] and Table2018[Place]. Your whole formula would look something like this
=SUM(COUNTIFS(INDIRECT("Table"&ROW($A$2015:$A$2018)&"[Place]");B3;INDIRECT("Table"&ROW($A$2015:$A$2018)&"[Activity]");{"Paid";"Awarded"}))
and it must be entered using ctrl+shift+enter (you will see {} brackets around the function). This should work to make the function smaller and you will need only to change the cell reference each year instead of adding another sum, but the question is if the separate sums are not easier to read and maintain.

Excel multi variables and outputs

First of all, I am not VBA user.
And I have written a very complex Excel worksheet internally correlated with functions.
Let's say x as the value that I type in and y as some numbers I am trying to get eventually as a result of calculations.
So what I am trying to do is changing x values while saving previous y values.
It would nice if I could have y values in different cells depending on x values.
For example, if x is 3, y returns in cell B1, and if x is 4 y returns in cell B2.
It would be appreciated if anyone could suggest an idea for this problem.
I have to be honest and say that based on the limited information in your question, this is the sort of thing that VBA makes easier. With VBA, you have far more control over how output from calculations are displayed, so 'recording' results in a formated (historical) fashion is much easier.
Consider a typical Excel Based Invoice system (I'm talking about freebies to download). You have a worksheet that looks like an invoice - it has boxes for text, lines for items, quantity, cost. It totals it all up at the bottom (all using formulas). You can manually print the invoice and that's fine. But you want to record the data to view again later? Rather than 'copy' the worksheet, most of the examples you'll find have a button (with VBA code), to store just the data (without the 'invoice' formatting) on a separate sheet.
Whilst you said that you're not a VBA person, you haven't specifically said that the solution must be a formula. Therefore, I have to say that in my opinion, the solution is definitely VBA and that's where you should be looking. Happy to create some example code to point you in the right direction if you agree.

Excel cell only updates after a second cell has been changed

Update: File
Upon request, I am including the link to the file: here. File no longer available
I have transformed my original data into a game-like context, in which the sheet keeps track of points for completed activities and upon reaching various point amounts, the user goes up in rank. An easy way to see the issue is to enter a 1 (and then 2 and 3) into F15 next to the cell with 500. When you do so, notice how the values in Q5:Q6 change from 0 to 1, but Ranking in C2 which is the SUM function which counts this range does not increase to 3 like it should. And consequently the values in L12 and L14 which are based on it also don't update. Now, if you recalculate, the rank goes up and the L cells update. NOW, cell E3 which is based on the L cells doesn't reflect the correct value, and you have to once again recalculate the sheet for it to update.
Hope all that makes sense - let me know if you need any clarification!
Original Question
Some of my formulas are not updating right away after I have entered in data. Just to get this out of the way before someone suggests it, I DO have the calculation of the workbook set to automatic, and I DON'T open any other workbooks with their calculation method set to manual. So that's not the issue.
I would give specifics on formulas, but I don't think it has anything to do with that. The formula is a simple SUM function which adds together a range. The range updates properly - as soon as I've entered data, the numbers in the range change accordingly. The SUM function should likewise automatically update, but I have to enter data in another cell or press delete in an empty cell (basically, get the sheet to recalculate once again) to get the SUM function to reflect the changes in the range.
The only thing that I can think is that it's because I've enabled iterative calculation (in File > Options > Formulas tab) in order to allow cells to retain their previous value if a certain condition is true, else update their value. My settings are 1 for Maximum Iterations and the default of 0.001 for Maximum Change. However, I've used that before without having issues with a simple SUM function. And I have other just as simple functions in my sheet that DO update properly, so I'm a little confused...
Let me know if any more info would be helpful. Thanks for any suggestions!
UPDATE:
Sorry, I didn't catch that this is for a formula, not function. My bad.
I'll leave the answer up in case someone has the same issue, but with a function. Sorry!
Try adding this inside the code:
Application.Volatile
This will force recalculation for the function each time a cell is changed on the sheet in which this function appears.
Reference: http://msdn.microsoft.com/en-us/library/aa213653(v=office.11).aspx
You have circular references: cell formula in range S4:AL103 all refer to themselves (under cetain conditions). This will cause excel to stop calculating because it can't resolve the conflict.
You wll need to redesign your formulas
Originally added to my initial post; moved it to an actual answer so that it could be accepted
So I figured out the solution. From doing a little more reading up on iteration, I discovered that in iterative mode, Excel processes cells one at a time, in a certain order (alphabetical, I think?). So if cell A is dependent on cell B, but cell B changes value later in the process, cell A will retain a value based on cell B's old value, rather than the new one, until another recalculation is prompted... OR, until another iteration starts. So, setting maximum iteration to a higher number than 1 fixes the issue. Since I had two cells not updating in the example sheet I gave you guys, it would need to be set at about 3. In my actual sheet, I had to set it at 5.
Thanks for the thoughts! Hope this helps some other confused soul!

Resources