Lookup table with variable breakpoints - excel-formula

BACKGROUND
Normally when I am dealing with tables to find values to work with the tables are nicely laid out with something like:
and I rearrange them to make my lookup life easier by converting the table to look like:
I toss in the extra column so that someone maintain the table in the future will have an easier time updating the table and formulas that refer to it. The formula I was using to for the table above was:
=INDEX(C3:I5,MATCH(MIN(B7:B8),A3:A5,1),MATCH(MAX(B7:B8),C2:I2,1))
Where B7:B8 had the dimensions I was referring to. Right now I am working with the assumption that large dimensions only come in set sizes. I would need to incorporate an interpolation approach if permitted and any sizes were used.
CURRENT ISSUE
Now I just came across a table that is making me really think about what is the best approach to the situation. The initial table looks like:
d/b | Cs | Kls
<=1 | - | 1
>1 | <=10 | 1
>1 | >10 but <Ck | 1-0.3*(Cs/Ck)^4
>1 | >=Ck | (0.70*E05)/Cs^2*fbu)
and my first go round at rearranging the table is:
d/b | Cs | Kls
0 | 1 | 0 | 0 | 1
1 | 1 | 0 | 10 | 1
1 | 1 | 10 | Ck | 1-0.3*(Cs/Ck)^4
1 | 1 | Ck | 9.99E+101 | (0.70*E05)/Cs^2*fbu)
So my two stumbling blocks is d/b can be any positive number 1.00001 or 0.99999 type deal. so the d/b lookup has me a bit concerned only for the moment as in the background example the first column I am checking against is >= values.
The second stumbling block I have is that the breakpoint for the second lookup value Cs has a variable for two of the break point ranges. The approach I was planning on taking here was simply calculate the value and pass it to the table when I go to do the look up. Now this approach works great for me when there is only one item to check. This approach I do not think will work when I have to deal with multiple items to check. Right now the only things I can think of are:
Each item would require its own table...which kind of defeats the purpose of the table.
convert the table to a nested IF function.
Its been a long day for me and the mind is a bit fried. I am wondering if anyone would care to share their insight on the approaches I am thinking of or has an approach of their own for a table with a variable as a break point?
Ahh fiddle sticks! I just reread the question and I never stated I was trying to pull the formula/result from the third column (ie Kls). Told you mind was fried.
If I wind up going the nested if route I would use something like:
=IF(OR(E50<=1,E57<=10),1,IF(E57<E63,1-0.3*(E57/E63)^4,0.7*G63/(E57^2*D71)))
Where
- E50 is b/d
- E57 is Cs
- E63 is Ck
- G65 is E05
- D71 is fbu

I think a nested-IF would be better than rearranging the tables. You are losing some values by rearranging the cutoffs.
In your first example, the smaller dimension has >64 but <114.
When you change that, you have 0 to 64, 65 to 114. What about 64.5? This value is not part of your table. Nested IF statements would allow you to keep the original values of the table. Also, you can use a named range for variables which are the breakpoint for the second lookup value Cs.

Related

How to get rid of #DIV/0! in excel...need non-geek response

I have searched the web for help in this issue, only to come across countless replies that simply throw a page long code up and expect us common folk to understand wtf they are talking about. So here I am, searching for someone who can guide me through this process like I am a toddler and not just reply with a link to some page-long code. I realize there is code involved, but I am not interested in a page long code for something that has to be much simpler. I simply want to remove these values from the rows, not do any math on the rows or anything. Whatever code you send me, please explain exactly what each set of cells means and how that is supposed to be input by me. Thanks for helping a dinosaur.
The error you are getting is because you are trying to divide something 0.
if you use this here in the Total column, =IFERROR(A2/B2, "") you will get a blank cell in place of that error.
A |  B |TOTAL (A/B) |
1 | 0 | |
2 | 1 | 2 |
3 | 2 | 1.5 |
4 | 3 | 1.333333333|
Puttin this in the total column and double clicking the little green square will copy this to all the cells below. If you still need clarification just comment.
instead of the empty space if you can add anything in the place of the error. Like =IFERROR(A2/B2,"THIS IS AN ERROR!!") and if there are any of those error bugs "this is an error" will replace it.

Searching in Excel for certain values, if found give text from cell to the left of where we found the value

First let me explain what I want to achieve.
I currently have an Excel like this:
Names | Standards
James | Standard 1
James | Standard 2
James | Standard 3
Francis | Standard 1
Francis | Standard 2
Francis | Standard 3
Leon | Standard 2
Leon | Standard 3
Peter | Standard 2
Michael | Standard 3
And I want to create something like this:
Standard | Name 1 | Name 2 | Name 3 | Name 4
Standard 1 | James | Francis | |
Standard 2 | James | Francis | Leon | Peter
Standard 3 | James | Francis | Leon | Michael
My real Excel has more than 300 standards, so I would like to automate this using Excel Formula. I know this is possible, but I haven't used Excel in a while, so I could use a push in the right direction.
Couple of things I need (I think):
Need to count how many times people in the names column mention a standard. So I want to know that I need 2 names for standard 1 and 4 for standard 3. I think I can do this by using the COUNTIF method.
We need to search for the location of the standards. I think I can do this by using the Match function. This gives us the location of the first match in my original Excel. By sorting my original Excel a-z and combining it with the countif result I know where all the matches are (first match + countif = location of the last match, and everything inbetween is also that standard).
For the first name that mentioned a standard, I will reference the cell left of the first match (because the names are in the cell to the left of the standard I found). For the second name I will reference the cell left of the cell below the first match. I keep doing this till I find as many names as Countif mentioned. So I need an IF statement that makes sure that if 2 people mention standard 1 only gets 2 names and 2 cells with a "".
How will I reference the cells? By another if statement that uses this: Excel Reference To Current Cell , Correct me if I am wrong, but can't I then just say THIS.CELL=cell location I found (probably should use INDIRECT here?).
This is just me brainstorming, but I would love to know if people have any other ideas for my problem or have some feedback for my current plan.
An important thing to mention is that I want to do this using Excel Formula. I do realise that this isn't always the best, but VBA is not an option atm. I am also not worried about performance issues, because I think i'll just copy all the values after I found all the names using formulas.
Thanks in advance!
Depending on how you want to have the layout, I think you should use a pivot table. Drag the 'Standards' and 'Names' fields to the 'rows' data box and then right-click on a standard, click 'Field Settings' - 'Layout and Print' - 'Show item labels in tabular form'. (See example below.)
If you definitely need the data in the format in your question, I would edit the pivot table by dragging the 'names' field to the 'columns' data box. Then drag the 'standards' field from the field list above a second time and duplicate it in the 'values' box (see example below).
In the space underneath the pivot table, use an IF formula to only copy the name if there is a 1. This kind of approach will obviously be quite fragile, so if you can make do with the first approach, I think you will run into fewer problems in the future.

VBA creating a Userform single cell object

I've developed an application that uses excel/ VBA to interface a MySQL database in a WAMP configuration. One of the features of this application is the automatic saving of cells values, including the colors of words, font style, font size etc. The application loads up a calendar and renders the entered cell text upon workbook open.
This is achieved through breaking down the cell value into characters and storing them into a cell_value table that references other objects within my database in the following manor
+----+-------------+------------+------------+----------------------+--------------------+
| id | employee_id | project_id | date | cell_value | font_color |
+----+-------------+------------+------------+----------------------+--------------------+
| 1 | 1 | 1 | 2015-01-07 | the weather is crazy | 1:14:70,15:20:2000 |
+----+-------------+------------+------------+----------------------+--------------------+
this table stores the text entered by person with id=1 for project with id=1 on '2015-01-07'. The cell value is 'the weather is crazy'. the font color is listed in a comma delimited string with each element of this string delimited by a colon.
+--------------------------+------------------------+------------+
| starting_character_index | ending_character_index | font_color |
+--------------------------+------------------------+------------+
| 1 | 14 | 70 |
| 15 | 20 | 2000 |
+--------------------------+------------------------+------------+
I have been using the cell_selection_change event to trigger an automatic write to the database to store the contents of a global called LAST_SELECTED_CELL (as the active cell is set prior to the user making changes to it and hence does not cater for writing to the database AFTER the user makes changes to the contents of the cell).
this method works although is prone to bugs and for large amounts of cells and complex cell font/ color configurations is slow.
I was looking into using a spreadsheet embedded into a userform as potentially a better way of doing a similar process however i've found it to be quite buggy and prone to crashing. Is there a tool out there that allows you to embed a single excel 'cell' into the userform instead of an entire workbook?
If not, is there anything else that could be modified to suit my needs? Or do you have any suggestions as to how to improve my current method of storing/ rendering the data
Kind regards
Jordan
You can't. There is no way to embed Worksheet into the userform. But...
You can imitate it via using ListBox. It provides a way to display data as Excel Sheet displays rows and columns. It gives you a possibility to select single row or multiple rows at a time. You can make visible only one column, the rest of columns can be hidden (use ColumnWidth property).
Cheers
Maciej

Excel Advanced filtering multiple columns with multiple acceptable data combinations

I have a large data set with 4 columns of interest all containing text, namely pokemon moves. The columns "move 1" through to "Move 4" each contain a different move, and each row differs in the combination.
eg.
" A | B | C | D | E".
" 1 Pokemon | Move 1 | Move 2 | Move 3 | Move 4".
" 2 Igglybuff | Tackle | Tailwhip | Sing | Attract".
" 3 Wooper | Growl | Tackle | Rain Dance| Dig".
~ 1000 more
My issue is this:
I wish to filter this data set for rows (pokemon) containing a certain combination of moves from a list.
eg. I want to find which pokemon have both "Growl" and "Tackle". These moves can appear in any of Moves 1 to 4 (aka order of the moves is unimportant)
How would I go about filtering for such a result. I have similar situations in which I would want to search for a combination of 3 or 4 moves, the specific order of which is not important, or also search for specific pokemon possessing a specific combination of moves.
I've attempted to use functions such as COUNTIF without avail.
Help / Ideas are much appreciated
There are a number of options for advanced filtering in excel that you might consider:
Option 1 - Advanced Filters
Advanced filters give you the power to query over multiple criteria (which is what you need). You can also easily do it as many times as you want to generate the final datasets using each filter. Here is a link to the advanced filter section for Microsoft Excel 2010, which is virtually identical here to 2007. It would be a great place to start if you want to move outside of just using basic formulas.
If you do go down this route, then follow the directions on the site in terms of steps:
Insert the various criteria that you have selected in the top rows in your spreadsheet and specify those rows in the list range
Set the criteria range to the place holding all your data on a single worksheet
Run the filter and look at the resulting data. You can easily do a count on the number of records in that reduced data set.
Option 2 - Pivot Tables
Another option that you might look at here would be to use Pivot tables. Pivot tables and pivot charts are just phenomenal tools that I use in the workplace every day to accomplish exactly what you are looking for.
Option 3 - Using Visual Basic
As a third option, you could try using visual basic code to write a solution. This would give you perfect control as you could specify exactly the ranges to look at for each of the conditions. Unfortunately, you would need to understand VB code in order to use this solution. There are some excellent online resources available that can help with this.
=COUNT(INDEX(MATCH(B2:E2, MoveList, 0), 0)) > 0
will return TRUE if any of the values in the range B2:E2 (Moves 1 through 4) are in the range defined by Move List. You want to use a named range so that you can easily copy this formula down for all of your thousand rows.
If you remove the last part that checks whether the COUNT() value is greater than zero, you get:
=COUNT(INDEX(MATCH(B2:E2, MoveList, 0), 0))
which will return the number of moves that the Pokemon has that match a move on the move list.
MATCH() takes three arguments: a lookup value, the lookup range, and the match type. I don't fully understand why, but wrapping that part of the formula in INDEX() seems to let you use an array for the first argument. Maybe someone here can provide a better explanation.
In any case, the formulae above do appear to solve the problem.
Finally, if you're only checking for a few moves, instead of using a confusing formula and a named range as above, you could just make a column for each move that you want to check for, e.g. "Has Growl?" and "Has Tackle?". You would then just use =COUNTIF(B2:E2, "Tackle") and =COUNTIF(B2:E2, "Growl"). You could then make another column that sums these columns and filter out the zero values to display only Pokemon who have Tackle or Growl.
I looked at these two pages when researching how to accomplish this:
https://www.excelforum.com/excel-general/786407-find-if-any-value-on-one-list-exists-on-another.html
https://www.deskbright.com/excel/using-index-match/

Excel Formula for dynamic columns

I'll try to make sense of this the best I can. I'm pretty horrible at making things clear. :) So...here it goes....
I have a spread sheet that is a list of seeds I have for growing peppers. Here are the columns I have, and I will explain more after.
Crop | Color | Generation | Species | Source | Scoville | Flavor | Heat | Notes | 2012 Type | 2012 Name 1 | 2012 Name 2 | 2013 Type | 2013 Name 1 | 2013 Name 2 | etc.
Ok. So "2012 Type" is a list that will contain either a blank, "N", "O", or "M". All I care about is whether it is blank or not for this question. If it is NOT blank I want to highlight the Crop name with a green background to show that I have grown this crop. To do that through the Conditional Formatting is a no brainer. However, my issue begins when I, as usual make things more complicated. When I add "2013 Type", "2014 Type", etc. I want to check for those also. So then my formula becomes an OR; is there a value in 2012 or 2013 or 2014, etc. Part of question is that. How do I write a formula that is dynamic enough to pickup the new fields I add each year...2015 Type, 2016 Type...etc.?
I also have a ton of other stuff going on, but I think I may have that figured out...sort of.
Thank you for your help, appreciate it.
Edit: Okay. I feel I need to explain how I am trying to develop my whole worksheet, one to check my thinking, and two to clear up the goals.
In addition to what I have explained above, I have tabs that read 2012, 2013, grown, not-grown, MasterList, and Criteria.
MasterList is what we are talking about here.
Criteria is what I am using for an advanced filter to copy crops that to the appropriate sheets. So, if I have a a crop marked in column "2012 Type", then it will be copied to the 2012 sheet. It will also be listed under the tab Grown. Same if it were marked under "2013 Type" etc.
Basically, I am using tabs to filter out specifics from my MasterList so that I can find what I'm looking for quickly, or view everything as a whole.
Once again, I am great at making things over complicated. Couple that with the fact that I am still fairly new to Excel coding...and you have a disaster. :)
Thank you all for listening. :)
Try using a COUNTIFS formula in conditional formatting, e.g. this formula
=COUNTIFS($1:$1,"*Type*",2:2,"<>")
....will count the number of cells in row 2 which have some value....and where row 1 has "type" contained in the header row for the same column.
For your condition you want to know whether the result of the COUNTIFS formula is zero or not (zero signifying no entries in any of the type columns for that row) so for green use
=COUNTIFS($1:$1,"*Type*",2:2,"<>")>0
Note: COUNTIFS is only available in Excel 2007 and later, for earlier versions you can use this formula
=SUM(ISNUMBER(SEARCH("type",$1:$1))*(2:2<>""))>0
Actually for an annual exercise I would just go for amending the conditional formatting as part of your procedure when you add the columns with the OR in it as you mention it.
The condition should be (as you probably already know):
=OR(ISBLANK($J2),ISBLANK($M2))
I'll have another thought about making it smarter but I have a feeling already that will involve some more coding and such, making the effort for this bigger then the benefit for the annual updates.
You might consider reformatting your data so that it only grows in the row direction and not the column direction. I'm thinking
Crop | Color | Generation | Species | Source | Scoville | Flavor | Heat | Notes | Year | Type | Name 1 | Name 2
Then you could use pivot tables, formulas, and array formulas to present the data in various ways.
I would create a worker column(you can always hide it later) that concatenates all your Type columns together into one column:
=CONCATENATE(K2,N2,Q2,T2,W2,Z2,AC2,AF2,AI2,AL2,AO2,AR2,AU2,AX2)
=$A$2:$ZZ$10000
=IF($A2="",FALSE,TRUE)
It's important that you enter the formulas and conditional format formulas and applied to range accurately - with the correct syntax(notice the use of $).
Good Luck.

Resources