If the answer was already provided, please feel free to post the link, but I did not see one.
This is a real estate example. I have a table of a lot of properties and information. One of the fields is "Occupancy." I am trying to use the AVERAGE OFFSET functions combined with CELL and INDEX/MATCH to calculate the average Occupancy of the top 5 and top 10 buildings in this table. To accomplish this, I wanted to create a "Summary Table" below the Property table to list the averages.
Specifically:
For OFFSET, in the "Reference" section, I want to look up "Occupancy" in my summary cell, use INDEX MATCH to find "Occupancy" in the table, and then;
I want the Cell Reference returned AS A VALUE and then move one row down and then highlight the top 5.
Most importantly, I want everything cell referenced without hardcoding or navigating the table to highlight the cell reference. I am not sure if this is possible, but after pouring through a bunch of articles, I am having trouble finding a solution.
To make things simple, let's pull out all the columns I had in the original table and go off the below. Assume all the data types are in the proper format:
**COLUMN A** **COLUMN B**
ROW 1 | Properties | Occupancy |
ROW 2 | Property A | 58% |
ROW 3 | Property B | 56% |
ROW 4 | Property C | 77% |
ROW 5 | Property D | 85% |
ROW 6 | Property E | 92% |
ROW 7
ROW 8 |Top 5 | | 'NOTE: I used a custom formula to format:
"Top "#. Please do not think this is text.
ROW 10|Occupancy | **CODE HERE**| 'Format is "General"
ROW 11| | |
ROW 12| | |
Here's how I initially coded it in B10:
'=AVERAGE(OFFSET(CELL("address",INDEX($A$1:$B$1,MATCH(A10,$A$1:$B$1,0))),1,0,5,1))
I am getting "there is a problem with your formula" since I am guessing it is due to the cell returning text in lieu of the cell reference as a value. So I error checked myself and stripped out the AVERAGE, OFFSET and put this is B11:
'=CELL("address",INDEX($A$1:$B$1,MATCH(A10,$A$1:$B$1,0)))
I know I get $B$1, so I then put $B$1 to replace the CELL function within B10 to see if my average offset is wrong:
=AVERAGE(OFFSET($B$1,1,0,5,1))
I now get the right solution since I went and hardcoded the reference, which does not solve the issue.
If I use INDIRECT and then CELL in B12:
'=INDIRECT(CELL("address",INDEX($A$1:$B$1,MATCH(A10,$A$1:$B$1,0))))
I then get the title "Occupancy" and not the cell reference.
Obviously, I am aware of the fact that the CELL function will return text and not a value. I can't use INDIRECT because when I do, INDIRECT will just display the title of the column in text and not return the cell reference as a value. ADDRESS is not useful because you have to hardcode and the goal is to have zero hardcodes.
How can I code finding the cell reference of specific text in a table without actually going to the table to cell reference when I am building out my OFFSET function?
As you can see, I went through a variety of ways to dissect the problem and I would appreciate anyone's help to come to a solution. Thanks in advance.
Related
I need to return in a cell all the cell values where the cell next to it contains a value range.
For example, if I have a table like this:
|Name |Evaluation
|------|------
| John | 3
| Sue | 4
| Jim | 2
| Andy | 6
| Tim | 1
| Bruce| 4
I'm looking for a formula to have all the names whose evaluation is >= 4, so, if applied to the table it should give as output in a single cell:
Sue
Andy
Bruce
I've already tried VLOOKUP, INDEX, MATCH and FIND functions but they all return a single value (the first cell that match) and not all of them.
If possible, I'm looking for an Excel Formula and not for VBA (this way I can share it easily with my working group that, as myself, is not very proficient in VBA).
Thank you very much!
=IF(B1>=4,A1,"") write the command in c1 column and drag the C1 column to the end of the column till the end name
(assuming you write first name in A1 column and Evaluation in B1 )
I've solved the issue by using (partially) the solution posted by dhS and a support table.
I've created the support table of the same height of the original one. This table goes from F1 till F120 (the end of the original table).
In the first cell i've used the formula
=IF(B1>=4;$B1;"")
In all the subsequent cells (from the second to the final one)
=IF(B2>=4;IF(F1="";B2;F1&CHAR(10)&B2);F1)
This way, in the last cell there will be all the names separated by a return (CHAR(10)).
To anyone who want to use this solution, remember to enable the Wrap Text option on the cell, otherwise you won't be able to visualize the returns.
Thanks to everybody for the help you gave me.
I have data like the following in cells A1:F4.
Quarter | FY15Q4 | FY16Q1 | FY16Q2 | FY16Q3 | FY16Q4
Company A | 0.34% | 0.48% | 0.55% | 0.68% | ------
Company B 0.32% 0.36% 0.34% 0.35% 0.35%
Company C | 1.18% |------ |----- |----- |
I'm trying to find the average of the most recent non-missing value from last 4 columns in each row. So for:
FY15Q4, I want the average of 0.34%, 0.32%, and 1.18%
FY16Q1, I want the average of 0.48%, 0.36%, and 1.18%
FY16Q2, I want the average of 0.55%, 0.34%, and 1.18%
FY16Q3, I want the average of 0.68%, 0.35%, and 1.18%
FY16Q4, I want the average of 0.68% and 0.33% (Company C has no data for the most recent 4Qs, so it is to be ignored from the calculation of the average)
The following array formula works as I want for FY16Q3...
{=AVERAGE(IF(COUNT(B2:E2)=0,"",INDIRECT(ADDRESS(ROW(B2:E2),MAX((B2:E2<>"")*COLUMN(B2:E2))))),IF(COUNT(B3:E3)=0,"",INDIRECT(ADDRESS(ROW(B3:E3),MAX((B3:E3<>"")*COLUMN(B3:E3))))),IF(COUNT(B4:E4)=0,"",INDIRECT(ADDRESS(ROW(B4:E4),MAX((B4:E4<>"")*COLUMN(B4:E4))))))}
But for FY16Q4, the same formula structure...
=AVERAGE(IF(COUNT(C2:F2)=0,"",INDIRECT(ADDRESS(ROW(C2:F2),MAX((C2:F2<>"")*COLUMN(C2:F2))))),IF(COUNT(C3:F3)=0,"",INDIRECT(ADDRESS(ROW(C3:F3),MAX((C3:F3<>"")*COLUMN(C3:F3))))),IF(COUNT(C4:F4)=0,"",INDIRECT(ADDRESS(ROW(C4:F4),MAX((C4:F4<>"")*COLUMN(C4:F4))))))
returns the #VALUE error value.
It seems that the AVERAGE function, which usually deals well with blank cell ("") values, is struggling because of the added complexity of the array formula.
Any suggestions on how I can make this work without either (i) using find-and-replace to replace "" with a truly blank cell; or (ii) using VBA?
Surely there must be a way to make this work using only formulas...
One method without array formulas is to use helper cells. I set up another table with the same column/row headers.
Then in the first cell I put:
=IFERROR(INDEX($A:$F,MATCH($A12,$A:$A,0),IF(MATCH(1E+99,INDEX($A:$F,MATCH($A12,$A:$A,0),1):INDEX($A:$F,MATCH($A12,$A:$A,0),MATCH(B$11,$1:$1,0)))<=MATCH(B$11,$1:$1,0)-4,NA(),MIN(MATCH(1E+99,INDEX($A:$F,MATCH($A12,$A:$A,0),1):INDEX($A:$F,MATCH($A12,$A:$A,0),MATCH(B$11,$1:$1,0))),MATCH(B$11,$1:$1,0)))),"")
Then drag it across and down to fill in the table with the correct number:
Then it is just a simple AVERAGE() formula:
=AVERAGE(B12:B14)
Which when dragged over will ignore the blank cells.
A few caveats put out by #Jeeped and #XOR LX.
This only works if the "Blank" are NOT 0 formatted as something else.
As companies and quarters are added the reference table will need the same columns and rows added.
I have spent the day trying to learn vba code and searching other questions for the same example but have been unable to crack this so help would be greatly appreciated.
I have worked out how to do it in vlookup but only to a single row.
This code from kutools is the closest i could find and almost does what i need but is only reading single digits in my range (which goes up to 700) so the value i return is multiples of the value string. This would need to be modified to only search and replace the specific value. http://www.extendoffice.com/documents/excel/1873-excel-find-and-replace-multiple-values-at-once.html
I have 3 columns: A has a random list of numbers, many repeating; B has a list of reference numbers which correlate to a place name in C.
A | B | C
1 | 1 | Melbourne
1 | 2 | Adelaide
1 | 3 | Sydney
2 | 7 | Auckland
2 | |
3 | |
7 | |
The code should result in the number in column A being replaced by a place name from column C by first finding the matching number in column B. Note: There are less rows in columns B&C than there are in column A.
There are thousands so i need a code to do this.
Thanks in advance.
Well first off I'd place the VLOOKUP data into a new column so to preserve your original data set, but here's the code that you should be looking for:
=VLOOKUP(A1,$B$1:$C$4,2,FALSE)
Here's the syntax of a VLOOKUP:
=VLOOKUP(lookup_value, table_array, col_index_num, [range_lookup])
Now for each part. The lookup_value is what you're using as a reference to search for, this will be your information for columb A. The table_array is a static reference of where to look for this value, and then the resulting values you want to display, so in your sheet you'll make this all of columb B and C. The col_index_num represents the index of the table_array you chose previously, so since the name of the cities is in the second column of this table, we put 2. range_lookup is whether or not you want an exact match. We do, so we set it to true. And then you can just replicate this value down a column to have the results for everyone.
That should be exactly what you're looking for. I even created a test sheet to try it out. In the future I suggest posting the code you've already tried.
I've used VLOOKUP plenty of times, but this has really stumped me. I have a VBA code that copies data from one workbook to another and then I'm trying to perform the VLOOKUP on the data that I've copied.
Here's an example of how the data I've copied is layed out in Sheet2:
5009 | Materials | Store Items
The table that has been copied is given the name "AutoList" for the range of the table (Theres a lot more than this obviously)
The table I'm trying to use the VLOOKUP on looks like this:
[VLOOKUP] | Materials | Z | X | C | V
The formula I am using is:
=VLOOKUP("Materials",AutoList,1,0)
I can't for the life of me figure out why I am getting #N/A as the result. If I remove the 0 on the end (for the logic), I end up with the last number in the AutoList table for every result as it's only doing a partial match.
Any help would be appreciated!
Is the "lookup_value" in the first column of your "table_array"...?
According to Excel's help file vlookup looks, "for a value in the leftmost column of a table." Does AutoList define your range with "Materials" in the first column? If so, then shouldn't the result of your vlookup formula return "Materials"?
I have a basic financial spreadsheet that I am trying to make even nicer. I have a table that looks like this:
| Description | Category | Amount
| 2341234 Chick-fil-a | Eating Out | 5.89
| 11234 Redbox/Georgetown | Entertainment | 1.21
And another table that looks like this:
| Name | Category |
| Chick-fil-a | Eating out |
| Redbox | Entertainment |
I want to find the strings from the first column of the second table in the first column of the first table and automaically populate the second column of the first table. I am pretty sure I can find the position of the string by doing a {=find(2ndSheet!A:A,1stSheetA:A)} or something of the like, but I have no idea how to populate another cell based off of that.
Does it have to be a macro?
This is a bit ugly but seems to work. It handles the situation where your description may not necessarily match the lookup table (for instance, with Redbox | Redbox/Georgetown). Replace the [Lookup_Table] with the absolute range of your lookup table, and enter as an array formula (Control+Shift+Enter):
=INDEX([Lookup_Table],MATCH(TRUE,NOT(ISERR((FIND([Lookup_Table],A2)))),0),2)
As for what it's doing:
=INDEX(
[Lookup_Table],
MATCH(
TRUE,
NOT(ISERR((FIND([Lookup_Table],A2)))),
0),
2)
It's using an INDEX formula with the [Lookup_Table] as the base range. For the row to match, it looks for instances where running the FIND formula using the current cell does not cause an error. So in the case of Redbox, you'd get an array like {#VALUE!, 7}. You then set the values to TRUE/FALSE based on whether they are errors, and then flip them so that non-errors are True. You then match the TRUE condition against that array, and a hit will return the row number in your lookup table. You then use that row number and column 2 to find the corresponding value.
Again, that is not a pretty one (and there is probably a better way to handle all of your cases), but it seems to work in my extremely exhaustive test of three rows :)
Assuming that your first table is starts in column A, substituting this formula starting in B2 should find the value for you.
=VLOOKUP(RIGHT(A2,LEN(A2)-FIND(" ",A2,1)),[Range of Helper Table],2,FALSE)
You'll need to substitute [Range of Helper Table] with the actual range. Make sure you use absolute references using $, for example: 2ndSheet!A$2:B$20. so that you can copy and paste.