Create a variable that stores value in excel - excel

Can I create a variable in excel maybe by using macro or anything more simpler, which stores my value and then uses that going ahead in formula,
My main problem is, I am trying to make a formula for calculating Compound Interest monthly, so for Example: I invest Rs.2,00,000 # 10% p.a interest rate.
In normal method I have to do:- 200000*(10%/12) which will give 1666.67, Now i will add (200000+1666.67)*(10%/12) which will give one value and so on.
So i want to create something that can store the Principle amount and Interest each months.
Also i cannot use compounding formula since, lets say in first month i invested only for last 5 days of the month, then interest for first month will be calculated only for 5 months, and then computation of balance month will proceed.
Thanks in Advance. Do let me know if you want any more clarity.

By far the simplest way of storing a static value in Excel, without using any VBA at all, is just to store that value in a single cell. That cell may then be referenced in any formula.
For example if you stored a static value in cell A1, you would reference that value in formulæ as $A$1.
If you don't want the static value on the same spreadsheet on which you're working, then you can create a new sheet named "Static" (or whatever you like) - then reference the cell as Static!$A$1. The sheet may then be hidden if you like.
You speak about adding principal amounts and compound interest. The easiest way to do this would be in a simple table, where the first row contains the initial calculation (including a reference to the static value as above); then subsequent rows reference the row above by means of formulæ. Therefore values would be added and multiplied according to a running total from the row above.
From your question, the specifics are not clear - so if you need more help than this, you'll have to give an example of what actual output you want - including several example rows.

You can also create/use a Named Range in your formula. To create a Named Range:
Formulas > Name Manager > New (Or type name in Name Box as seen in below photo)
This will create a locked reference to a cell (or block of cells for other scenarios) that can be referenced in a formula by name. Make sure this cell has the value you want to reference of course.
For instance, if you name your range Principal, you can refer to the range (value) in a formula as such:
= 2,000 * Principal
This is essentially the same solution as mentioned above, but it may be more intuitive to reference a named range (Principal) rather a locked cell such as ($A$1).

Related

Find value in the same row of another value that has been looked up?

I looked up values from another sheet with the following formula:
=IFERROR(INDEX('Detail list'!$H$2:$H$1604;SMALL(IF(1=((--(A$1='Detail list'!$J$2:$J$1604))*(--(A$2='Detail list'!$I$2:$I$1604)));ROW('Detail list'!$H$2:$H$1604)-1;"");ROW()-2));"")
This lookup is based on two criteria: Company name and year.
The lookup happens in cell A3 and onwards. It uses the company name in A1 and the year from A2 and then finds a corresponding value in another sheet. There's duplicates involved here since the column that is used for this look up consists only of 001 up til 010. It still is able to return all the values in the correct sequence based on year and company name.
I now want to look up or couple a 'corresponding' value with the value that was just acquired. For example: The value in A3 (005) refers to a specific cell in the other sheet. I want to return a value from that exact row but a different column. I have tried the following:
=IFERROR(#INDEX('Detail list'!$B$2:$B$1604;AGGREGATE(15;6;(ROW('Detail list'!$H$2:$H$19883)-ROW('Detail list'!$H$1))/('Detail list'!$H$2:$H$19883=A3);COUNTIF($A$3:$A3;A3)));"")
This does return a value (namely a client value) but this it is not precise as it takes the first 005 it comes across in the full list (so no longer sorted on year and company!) and reports that. I need it to be from the exact row the previous value is referring to.
I'd be so happy if anyone could help me out with this one. If not, I understand completely,
Kind regards,
VHes
Keeping references consistent and clear across sheets while nesting statements can be tricky. Have you considered pasting the data from 'Detail List' into your current sheet and using something like VLOOKUP or INDEX that way?
Another possible solution would be to throw everything into a pivot table and use the filters to get what you need. Not sure if either of these apply to your task.

How can I make my function reference all the cells in my column that are being used instead of just having a broad function?

I have many formulas that reference a large list and at the time I just have them to 1000 to make it easy. There will come a day that I will surpass 1000 and I don't want to have to continuously update the function but at the same time I don't want to have an excessive range.
The following function is in cell CM4 and I have data in cells CM11:CM52 and each day one more gets added at the bottom. What kind of function could I use to just take the average of CM11:CM52 that will reference CM11:CM53 tomorrow and so on and so on?
The following formula is a simple one that is in my worksheet:
=AVERAGE(CM11:CM1000)
Many formulas do not have a cost to using full column references. AVERAGE() is one of them so there is no problem using
=AVERAGE(A:A)
Or if you want to start on a certain row:
=AVERAGE(CM11:CM1048576)
For those formulas that do matter ie Array Types then we can make it dynamic with INDEX/MATCH
=AVERAGE(CM11:INDEX(CM:CM,MATCH(1E+99,CM:CM))
If the column in question is text then use "zzz" instead of 1E+99
I would suggest adding your data to a table (insert>table). This will allow the formulas to update automatically.

How do I extract data from the same row of a maxif result on excel?

So I have a data set converted from a stock chart in 1 minute time increments and I want to extract key data points from the data set.
screenshot
The problem I am running into is when I attempt to use the INDEX function to match the MAXIF and MINIF results, the time criteria does not follow through:
The first function to extract the Low of Day from this data set:
=MINIFS(E:E, B:B, ">09:30", B:B, "<16:00")
The second function I'm attempting to pull the time of when the Low of Day data point is pulled from:
=INDEX(B:B,MATCH(MINIFS(E:E, B:B, ">09:30", B:B, "<16:00"),E:E,0))
The result I get is 8:52 AM, which is outside of the time criteria I have set. It appears that the function seems to pull the very first instance that matches the MINIF function result, disregarding the time criteria altogether.
So also I want to keep in mind that I want to use a function that does not rely on hunting down individual cells as I'm hoping the end goal is to automate a data extraction process to export all the significant data points into a new excel sheet, and doing this over the course of several hundred to thousands of data sets.
Ideally I'd like to have a function that can reference the exact data point that was first extracted to pull other significant data from the same row and avoid possibly referencing the wrong data point just because it's a duplication elsewhere.
Try the following array formula, which needs to be confirmed with CONTROL+SHIFT+ENTER...
=INDEX(B2:B10,MATCH(SMALL(IF(B2:B10>"09:30"+0,IF(B2:B10<"16:00"+0,E2:E10)),1),IF(B2:B10>"09:30"+0,IF(B2:B10<"16:00"+0,E2:E10)),0))
...and adjust the ranges accordingly. For efficiency, though, I would suggest that you avoid whole column references.
If the range grows over time, consider converting your data into a Table. The references will automatically adjust as rows are added or removed.
Notice that +0 is added to the time. This is to coerce the string value into a true time value.
EDIT
Since it looks like you don't want to convert your data into a Table, here's an alternative that uses defined names instead. Here too, the ranges will automatically adjust as rows are added/removed. Note that it uses Column B to determine the last row.
First, define the following names (change the sheet names accordingly)...
Name: LastRow
Refers to: =MATCH(9.99999999999999E+307,'Sheet 1'!$B:$B,1)
Name: TimeColumn
Refers to: ='Sheet 1'!$B$2:INDEX('Sheet 1'!$B:$B,LastRow)
Name: LowColumn
Refers to: ='Sheet 1'!$E$2:INDEX('Sheet 1'!$E:$E,LastRow)
Then try the following formula, which needs to be confirmed with CONTROL+SHIFT+ENTER...
=INDEX(TimeColumn,MATCH(SMALL(IF(TimeColumn>"09:30"+0,IF(TimeColumn<"16:00"+0,LowColumn)),1),IF(TimeColumn>"09:30"+0,IF(TimeColumn<"16:00"+0,LowColumn)),0))

Use INDEX/MATCH to select formula written as string, and enable it?

I have a pricelist, with currently 5 different categories of products. Each product will have to have two different prices. Depedning of the product and the type of price, the calculation will be different. Therefor I've used INDEX/MATCH to find the formula needed, from a table I created.
Below a screendump, and I wanted to attach the Excel fil, but canøt seem to work out how.
Question: HOW do I then "run" the formula I fetched? -I've tried different suggestions on using EVALUATION, but it doesn't seem to cut it? Also I've tried "Indirect' on the whole formula, without success.
I would like to avoid any VBA for this case.
Can anybody provide some insight?
You could but if I understand properly, the only thing changing in the formulas is the "muliplier" number, then it's better to lookup that number instead of the whole formula. The other method (which would use Evaluate etc) is not be considered "good practice" for a number of reasons.
EDIT:
I didn't see the 2nd varying value (since I was on the SO mobile app) but it's still not an issue since it would a target column. You could be thinking of the opposite: sometimes lookups based on multiple criteria can get complicated, but this a matter of more data, as opposed to adding criteria for the lookup.
VLookup would have been the simplest method, like G2 could have been:
=VLOOKUP(E2, $J$4:$L$8, 2, False)
...to return the second column of range J4:L8 where the first column equals E2. (Then for the next required column, same formula except with 3 instead of 2.)
Since I wasn't sure more columns could be added one day, I allowed for that by, instead of specifying "Column 2 or 3" etc, it finds the column dynamically by name. (So the multiplier/factor used in G2 will change if you change the title in G1 to the name of a different column existing in the target data chart.
For the sake of neatness as well as potential of additional columns like G & H, I moved the lookup table to a separate sheet. It can stay out of the way since you won't need to see or change it very often. (If the same chart was going to be referenced by many workbooks, you could even move it to a separate workbook and point all formulas at that, since it's always best to have one copy of identical data instead of many in different workbooks.
Also to assist with potential future changes (and just to be tidier), instead of referring to the target table range addresses (like "J4:L8" etc) I named two ranges:
the table of multiplier/factor data can be referred to by it's address, or by myMultipliers
the titles of the same table is also called myMultiplierTitles (used to match to the titles of column G & H on the original sheet.
Formula
After those changes, the lookup formula in G2 is:
=INDIRECT(VLOOKUP($E2,myMultipliers,MATCH(G$1,myMultiplierTitles,0),FALSE)&ROW())*VLOOKUP($E2,myMultipliers,MATCH(G$1,myMultiplierTitles,0)+1,FALSE)
INDIRECT returns the value of a cell that you refer to by name (text/string) as opposed to directly (as a range). For example:
=INDIRECT("A1")
returns the same as
=A1
...but with INDIRECT we can get the name from elsewhere (a cell, function or formula). So if x="A1" then =INDIRECT(x) returns the same as the 2 above examples.
Your original plan of storing the entire formula in a table as text would have worked with the help of INDIRECT and/or EVALUATE but I think this way is considered better practice partly because it facilitates easier future expansion.
The formula is longer than it would have been, but that's mostly because it's dynamically reading the field names. And size doesn't matter. :-)

Lookup table formula (trip planner)

I want to be able to dynamically add a value from a lookup table depending on whether or not a value exists.
This seems like a question that should be solvable with some kind of 'lookup' command, but I can't figure it out.
I've made this a public worksheet anyone can see: https://docs.google.com/spreadsheets/d/10r7oxMEFU6tpJ32zxSuzk4bEtWyAnb7PGtzDxBy8gq4/edit?usp=sharing
There are four columns of names, but it only needs to work with one (clearly).
Let me be more specific. In the linked Google sheet, cell B31 is key.
Here's the user experience: If you put a value into a cell then that means you (assuming you're Joe) want to visit that location for X days (whatever value you input). But then let's say you put another value in a cell further down the list, so now you want to go from the first location to the second, and spend Y days at this new location. The formula in cell B31 should use the table of hours from the "Distances" tab and add that time to the total time that it's calculating.
In this way you can magically plan your trip. The value at the bottom of the column (B31) will be the day your trip needs to finish on to do all the things you want to do, including the travel time between the locations you chose.
Went on a hike, realized I could use another column.
The answer is now on that public sheet, I created a new column for 'Joe' with the following formula which calculates the rolling new date.
=G2+B3+IF(ISBLANK($B3),0,(INDEX(Distances!$B$2:$AD$30,MATCH(INDIRECT("Trip Planner!A"&(COUNTA(B$2:B3)+1)),Distances!$B$1:$AD$1,0),MATCH(INDIRECT("Trip Planner!A"&COUNTA(B$2:B3)),Distances!$A$2:$A$30,0)))/24)
Basically, the logic goes, take the previous time plus the time spent at this location... THEN (assuming the value at this location exists) use 2-column lookup (that is, an index with two match calls) to dynamically find the distance from the last visited location to this one... and add that distance to the mix.

Resources