VLOOKUP as a range - excel

I have a table in a tab with columns: street_id, street_name, street_corner_1 and street_corner_2 (a street corner is the name of the street that intersects it at the beginning or end).
So I have in another tab a table where columns go through street1 to streetn, rows work the same (like a matrix), and I want to check if the name of the street of row 1 (street1) is either the street corner 1 or 2 of street2.
What I wanted to do is format the cell so =COUNTIF(VLOOKUP(street2;street_id:street_corner_2;{3;4}),VLOOKUP(street1;street_id:street_name;2))>0
So, the range for the countif would be the two street corners of street2 and the criteria would be the name of street1, and the cell would be 1 if the name of street1 is among the corners of street2 and 0 otherwise.
I want to define the range with VLOOKUP, how can I do this?

I made a fake dataser including a street map to see if this what you mean. You want a matrix table with the first and last intersection and check if it's corner 1, corner 2 or nothing.
You can do it with 2 VLOOKUPS. My formula is (note I'm using mixed references so I can use same formula for all columns and rows):
=IF(I$1=$H2;"-";IF(VLOOKUP(I$1;$A$2:$D$5;3;FALSO)=$H2;"Corner 1";IF(VLOOKUP(I$1;$A$2:$D$5;4;FALSO)=$H2;"Corner 2";"-")))

Related

Swapping street names

I have a list of street intersections in excel. Of course it reads S 74th St / Rogers Ave as being different from Rogers Ave / S 74th St. I am trying to swap the cells on the columns so that intersections like that all end up looking the same. I have broken them down into two columns and having been trying the iferror/index/match functions but obviously not doing it right. If there is a macro I could write, that would be ideal. Any ideas?
Assuming your data always appears in a single Cell, in the format "[Street 1] / [Street 2]", this can be done with some helper columns.
First in column B, use the following formula, which will pull out the left name from the intersection:
=LEFT(A1,SEARCH(" / ",A1)-1)
Then do a similar thing in column C:
=RIGHT(A1,LEN(A1)-SEARCH(" / ",A1)-2)
Then, in column D, you will create a new text string showing the intersection, sorted [sort of] alphabetically by the first 4 characters of each road. You can do this as follows:
First, consider the below formula, which picks up the ASCII character value of the first 4 characters of the word found in B1:
=SUM(CODE(MID(LOWER(B1),{1,2,3,4},1)))
This creates a single number which equals the sum of the specific code for each character. We can use that to sort the priority of one cell over another, by comparing with the sum of the same formula for the cell in C1, like so:
=SUM(CODE(MID(LOWER(B1),{1,2,3,4},1)))>SUM(CODE(MID(LOWER(C1),{1,2,3,4},1)))
This will show TRUE if the sum of those codes in B1 is bigger than the sum of those codes in C1. Put this formula in D1 and copy down.
Finally, recreate your ordered string as follows, in column E:
=IF(D1,B1&" / "&C1,C1&" / "&B1)
Now this can be used as a column of ordered data, which should eliminate matches in the streets [assuming no streets have the same 4 characters as any other, and no duplicate streets start differently - ie 5 Ave vs 5th Ave].

Find the nearest set of coordinates in Excel

There are two tables, each with a coordinate pair: longitude and latitude, in decimal degrees (i.e. 37.23222, -121,3433). How do I match table A with its nearest coordinate pair in table B?
You could try filling down this formula from G1 as shown below:
=LOOKUP(1,1/FREQUENCY(0,MMULT((B$1:C$10-E1:F1)^2,{1;1})),A$1:A$10)
For a more accurate formula that takes account of the circular distances try filling down from H1:
=LOOKUP(1,1/FREQUENCY(0,SIN((RADIANS(B$1:B$10-E1))/2)^2+SIN((RADIANS(C$1:C$10-F1))/2)^2*COS(RADIANS(B$1:B$10))*COS(RADIANS(E1))),A$1:A$10)
This problem was solved back in 2006 by Tom Ogilvy here, also found here.
The sample that I created:
Original problem:
I have 20 named locations in a coordinates. Every point have x,y.
column a has the location name
column b has the x cooedinate
column c has the y coordinate
Now i have 400 coordinates in 2 columns (column e and f ) and want to
have the name of the closest location (of the 20 named in column a) in column g.
Original solution by Tom Ogilvy:
Assuming original data starts in A1, B1 and C1 with first locations in E1
and F1
If you don't want to fill your sheet with formulas, you can put this in G1
committed/entered with Ctrl+Shift+Enter rather than just enter since it is
an array formula, then drag fill it down the 400 rows.
=INDEX($A$1:$A$20,MATCH(MIN(SQRT(($B$1:$B$20-E1)^2+($C$1:$C$20-F1)^2)),SQRT(
($B$1:$B$20-E1)^2+($C$1:$C$20-F1)^2),0),1)

Generating letter by its position in the alphabet

I want a formula that can return the letter of the excel alphabet (27 = AA etc.) of a given number.
The purpose of this is that I have a table that returns values in a spreadsheet. I am summarizing data of climate measurements in cities, this data takes up 4 columns (but the same rows and relative positions in each column, so I29 and J29 contain 2 numbers I need, and then M29 and N29 contain the same data for the next location.
I want to create a summary table that looks like the below
City Rainfall Average Sunshine Average
City A =I29 =J29
City B =M29 =N29
City C etc.
my problem is that i go up to a few hundred cities, and i want to be able to populate the cells automatically/fill down. I know what row the data is in but need to generate the column letters using the formula requested above, so I can use a concatenate to create the cell reference.
You can use the ADDRESS function.
For example, =ADDRESS(29,27) will return the string "$AA$29".
However, honestly in your situation I would use the OFFSET function, combined with ROW(). To illustrate, let's say your table starts with a header row on row 50 and data starts on row 51. The data for a given city would start (ROW() - 51) * 4 columns to the right of I29. So:
A B C
50 City Rainfall Average Sunshine Average
51 City A =OFFSET($I$29,0,(ROW()-51)*4) =OFFSET($I$29,0,(ROW()-51)*4+1)
52 City B =OFFSET($I$29,0,(ROW()-51)*4) =OFFSET($I$29,0,(ROW()-51)*4+1)
53 City C etc.
Of course, you have to be careful if you want to move these cells around; you'll have to change the 51.

Creating a Top Ten list in Excel

I have been searching for a way to make a "Top Ten" list for my uncles hockey league in Excel.
There are 5 different teams with their own worksheets and I made a separate worksheet called "data" referencing all of the players and their individual stats so that I could pull my "Top Ten" from one worksheet instead of five.
The worksheet is setup as follows:
Player1 Player2 Player3 etc...
Name
Team
Goals
Assists
Points
I would like to search for the player with the highest number of "Points" and return the name, team, goals, assists, and points on a single row, and then move down for the next player, i.e.:
Name 1 Team Goals Assists Points
Name 2 Team Goals Assists Points
I have tried using multiple ways including index and hlookup with the large and match commands, but could not get anything to work.
I feel like I am missing something simple here.
If it would be easier to have the players in rows, I could do that.
I was just having a problem with my references filling in the way I wanted them to.
Initial table:
B1: =COUNTA(B6:O6)(the number of players)
B6:O6 Name
B7:O7 Team
B8:O8 Goals
B9:O9 Assists
B10:O10 Points
Formulae below determine the rank for the player. If the score of points are equal, the player having a greater number of goals ranks higher.
B4: =$B$1-RANK(B$10;$B$10:$O$10)+B8/1000, the formula is copied to the right. The result will be fractional numbers with equal integer parts for the equal amount of points.
B3: =RANK(B4;$B$4:$O$4), the formula is copied to the right
B2: =IF(COUNTIF(C$3:$O$3;B3)>0;B3+COUNTIF(C$3:$O$3;B3);B$3)
Ranked table:
A15 and down : Rank (1,2...n)
B15 and down : =HLOOKUP(A15;$A$2:$O$3;2;FALSE)
In the next columns: Name (col C), Goals (col D), Assists (col E), Points (col F)
C15: =HLOOKUP($A15;$A$2:$O$10;5;FALSE)
D15: =HLOOKUP($A15;$A$2:$O$10;7;FALSE)
E15: =HLOOKUP($A15;$A$2:$O$10;8;FALSE)
F15: =HLOOKUP($A15;$A$2:$O$10;9;FALSE)
Formulae in B11:E11 will be copied down.
Example spreadsheet: http://www.bumpclub.ee/~jyri_r/Excel/Top_players_matrix_transposed.xls
you have to transpose the table first..
select all the rows and columns of your table.
right click the first cell where you want to paste the table
click paste special option
check the transpose check-box in the dialog-box opened.
your table is now transposed. now simple sorting can give u answer
for sorting columns :
select the whole table and click on the sort option on menu bar,
now you can retrieve all 10 top teams from this sorted list.

Finding matching value in sheet 2 and copy adjacent cells value in sheet 1

I have searched through many similar topics but could find nothing that will do what I need.
I am trying to create a worksheet that will track scores for a darts game.
On Sheet 1 I have two columns that simply tracks each players throws from 501 down to 0
Row 25 is the amount remaining for each player.
In Sheet 2 I have 2 columns. The Column A contains scores that you can check out on, and Column B contains the checkout e.g. (T20, T20, D18). So if the value in row 25 of Sheet 1 matches any of the values in Column A of sheet 2, the I want to display the Value of Column B in the matching row on Sheet 2 Underneath the remaining score on Sheet 1.
Can anyone point me in the right direction?
not sure what you mean exactly, but this formula in row 26 should do the trick:
=index('Sheet 2'!$B:$B;match(A25;'Sheet 2'!$A:$A;0))
if your list separator is comma ,, use that instead of semicolon ;
you might want to use 1 as the third argument of match function, if you want to display the checkout according to the nearest match that is bigger than the number in row 25 and the column A in Sheet 2 is sorted in ascending order (1-9)
or -1 if you want the nearest match that is smaller and column A is sorted in descending order (9-1)
You can use this:
=IFERROR(VLOOKUP(A4, Sheet2!$C$2:$E$65535, 3, FALSE),0)

Resources