excel 2007 X Y lookup - excel

Good morning. I have been searching for some code either a formula or VBA to lookup values in a table. I have two tables that I am looking to migrate data from the old with the new. Both tables are relatively the same.
A B C D E
1 Store 1234 2345 3456 4567
2 1234 0 5 10 15
3 2345 5 0 20 25
4 3456 10 20 0 35
5 4567 15 25 35 0
It is basically a mileage table with location to location distance. I am looking for a way to take the values from the old table into the new when the row columns dont match up exactly due to new locations added.
I know how to do a vlookup, but that dosent do what Im looking for... I want a way for a formula or vba to something like "find Value in B2 "1234" where it intersects the value in D1 "2345" = D2 "5"

Should be able to do a Index and Match combo to find it. I1 = From, K1 = To you can just type in the locations into those cells and get the range out you want.
=INDEX(A1:E5, MATCH(I1,A1:E1,0), MATCH(K1,A1:A5,0))

Can you implement IF formula to vlookup? In abstract: =IF((vlookup)=something),do this, else)
I would be hapy to look into this issue further, if you could provide complete BEFORE data and expected AFTER data.
Also, maybe =DGET would work for you?

I used this formula slightly modified and it worked fine,
=INDEX($A$1:$G$7, MATCH(B12,$A$1:$A$7,0), MATCH(C12,$A$1:$G$1,0))
the first part of the equation is the entire table including the X and Y coords. the next two parts are the X and Y coords (you can swap these round if you wish)
so the requested information for x and y was put in cells C12 and B12 and all those cells below...
then I used the dollar symbol to fix all the other look up cells, so i could use auto fill, and entered this in E12 (this is where the result will appear.
You can see the table in the attached (or could if I was allowed to attach it). I am looking up B12 (3) in column A then looking up C12 (6) in row 1 and returning the value at the intersection (in this case returns "r").
or there would be an attachment if the stupid web page did not insist on having me obtain a 10 reputation... hopefully you get the idea...

Related

Excel copy format between cells using formulas

Hy everybody,
I have a question about the cell formatting in excel. I have a table like that, where I have a series of true/false values:
Next I have another page in which I use a formula to determine if a 1 on a row is present and copy it to a single vertical table, like that:
That is pretty simple, by using a nested if I can easily achieve this result. Here is an example:
=IF(PAG1!A1=1; PAG1!A1; IF(PAG1!B1=1; PAG1!B1; IF(...)))
So I can stop on the first one. Now the problem is that I have a series of colors that must be copied too. As you can see from the picture I need to copy also the green and the red from the table, because at last I need a result similar to this one:
Is there a way to obtain this result programmatically? Green and red ones can be everywhere each time the table changes so I need a way to copy the format dinamically. Actually my idea is to try to get somehow the cell reference from the if statement (any clue on that point?) and once having the origin cell try to copy the format for the new cell in the new page. Is there a better way to do that?
At least it will be good also to have another table where I report the cell reference, like: D1, A2 and B3, so I can write a VBA script to color the cell based on their origin. Is there a function taht can be used to achieve that?
Table where each row might have a single 1 on one of the columns starting at A2 for example, with 4 columns. Find the column where 1 might exist use the =MATCH() function
A
B
C
D
E
F
1
2
0
0
1
0
=MATCH(1.0,A2:D2,0)
3
1
0
0
0
=MATCH(1.0,A3:D3,0)
4
0
0
0
0
=MATCH(1.0,A4:D4,0)
This will return the index in the range where a match is made, or N/A
F
3
1
N/A
In this case the range includes columns A through D so 3=C and 1=A.
You can take it from here with VBA to find the cell in the table from each row and column information.

Excel - How to search a range for a specific substring and then output the whole value from the cell that the substring was found in?

I apologize for the long--and possibly confusing--question. I am trying to search a specific range for a substring, and if that substring is found within the range, place the FULL value of the cell where the substring was found into a different cell.
For my data set, I have broken up polynomials in such a way that they are listed from least exponent to greatest exponent. Each row contains a different polynomial in this form. The exponents can range from -13 to 16. What I want to do is search through each row individually and sort the data in such a way that the exponent matches which column it is in.
For example, here are some of my data and what I want it to look like after the sorting is complete:
-13
-12
-11
...
15
16
x**(-11)
3*x**3
-x**4
...
0
0
x**(-12)
-x**(-10)
1
...
0
0
...
...
...
...
...
...
This table above would turn into the following (with some column heading changed):
-13
-12
-11
-10
...
16
0
0
x**(-11)
0
...
0
0
x**(-12)
0
-x**(-10)
...
0
...
...
...
...
...
...
What I have tried so far:
I am very new to excel, so I have been aimlessly googling what I think might work and working by trial and error. From what I have tried, the following has brought me closest to what I am looking for:
=IF(COUNTIF(A3:AD3,"*"& "**4" &"*"),/*TARGET CELL*/, 0)
where A3:AD3 is a row that I am looking through and "**4" is the exponent I was trying to grab.
I am not sure what to do for the /TARGET CELL/ part, though.
Hopefully, my question makes sense. What I want may be impossible, but I appreciate and feedback or any other suggestions.
Thanks!
3 tables : Input tables, 'index' table, 'placement' table
Idea : use index match (or XLOOKUP) with string extraction.
Assume x**(-11) 3*x**3 -x**4 is in A1:C1 (table 1)
Do :
In cell A2 put =TRIM(A1)
In cell A3 put =LEN(A2)
In cell A4 put =FIND("**",A1)
In cell A5 put =A4+1
In cell A6 put =RIGHT(A2,A3-A5)
In cell A7 put =NUMBERVALUE(SUBSTITUTE(SUBSTITUTE(A6,")",""),"(",""))
and drag all to column C. Then
In cell I1 put 3
In cell J1 put -11
In cell K1 put 4
Then
In cell G2 put =IFERROR(INDEX($A$1:$C$1,MATCH(G$1,$A$7:$C$7,0)),"")
and drag till I2.
table 1 : A1:B1
table 2 : A7:B7
table 3 : G2:I2
by studying the A2:A6 formula you can see that it can easily be combined into one and generate A7:C7 directly.
As you can see, A7:C7 will we the 'address' for the content in A1:C1, given that the G2:I2 column headers (G1:I1) match.
Have a try & share if you get stuck in understanding it (or if it is working in your case).

excel, matching with greater than and lesser than and static values

I am trying to do in Excel what should be done in a database. I have a spreadsheet with raw data and which I am trying to query based on criteria. Given the following example table:
A B C D E F
1 Red up 1 4 dn 5
2 Blu up 5 9
3 Yel dn 1 4
4 Gre dn 5 9
I would like to return the value of column A that meets the criteria of E1 and F1 where E1 is found in column B and F1 is found equal or between the values in columns C and D. In the example, I would like to return "Gre".
I have been pulling my hair out with INDEX and MATCH functions and I can get part of my task done, but have found nothing extensible to solve the total solution.
Thank you in advance for your help!
Please try this...
=IFERROR(INDEX($A$1:$A$4,MATCH(1,INDEX(($B$1:$B$4=$E$1)*($C$1:$C$4<=$F$1)*($D$1:$D$4>=$F$1),),0)),"")
If you don't mind adding headings to your raw data.
You could use this formula:
=DGET($A$1:$D$5,"Field 1",$E$1:$F$2)
A1:D5 being your database.
Field 1 is the field to return values from.
E1:F2 is your criteria (field name and value to look for in that field).
https://support.office.com/en-gb/article/DGET-function-455568bf-4eef-45f7-90f0-ec250d00892e
As noted by #Vityata this won't work for the OP - looking for the value 6 would return a #VALUE error rather than Gre.
A couple of updates would allow it to work:
Updating the formula to: =DGET($A$1:$D$5,"Field 1",$E$1:$G$2)
Updating the table to:
The values in F2 and G2 are calculated as:
="<=" & $H$2 and =">=" & $H$2
This example would then return Yel when 1 is entered in cell H2.
I liked the question, thus I have elaborated a bit on the sktneer's answer.
The reason, it works is because we are looking for truth (a.k.a. 1) in the following formula:
=MATCH(1;
INDEX(($B$1:$B$4=$E$1)*($C$1:$C$4<=$F$1)*($D$1:$D$4>=$F$1););0)
Like this:
Then with an INDIRECT we may achieve the answer:
=INDIRECT(ADDRESSE(I1;1))
If you want it in one formula, it should be like this:
=INDIRECT(ADDRESS(
MATCH(1;INDEX(($B$1:$B$4=$E$1)*($C$1:$C$4<=$F$1)*($D$1:$D$4>=$F$1););0);
1))

Excel - Compare more than a column using VLOOKUP

I need to compare my list of latitude/longitude (columns 4 and 5) with a database containing latitude/longitude data (columns 1 and 2) and its associated data (column 3). This associated data I need to ascribe to the relevant latitude and longitude in column 6. There are no duplicates in the database.
I have tried to use the index functionality etc but have had little luck.
DatabaseLat DatabaseLon Data Lat Lon CopiedData
31.2 -87.9 5 30.5 -87.1 3
31.9 -88.3 6 31.9 -88.4 10
31.9 -88.4 10 54 -87.1
31.1 -87.2 2 31.2 -87.9 5
30.5 -87.1 3
This was something close to what you were looking forward to, by just using formula than a macro/script.
Essentially done using a concatenate function and VLOOKUP.
Step 1. concatenate value from your database and add it under Col A.
Step 2. Use VLOOKUP as in the image and compare using the concatenated value.
=VLOOKUP(CONACTENATE(H2,I2), $A$2:$D$10,4, 0)
Note: the syntax is using LibreOffice the function name may slightly differ.
Most likely you will have to:
Write a VBA Excell macro script link
Make use of for each loop, to go through every cell of column 4 and compare it to the same row of column 1.
If they hold the same value you just check column 2 and 5 simply by adding 1 to the current column number, which will move you to the right. eg.
if cell E5 == A1 then [E +1 = F ] if cell F5 == B1, you have a match. So you can extract from C1 the Database number.
Or, take a look at this methods link
I can't help more, I don't work on windows sorry, and good luck.

Copy data between excel spreadsheets with a given value as a parameter

Say I have two spreadsheets.
One of the spreadsheets has a table like this:
**Sheet 1**
A B C D
1 Name Age Rank Number
2 George 22 Master 12
3 Paul 21 Acolyte 22
4 Jimmy 32 Horse 33
5 Agnor 12 Cheetah 90
The other spreadsheet looks like this:
**Sheet 2**
A B C D
1 Name Age Rank Number
2 George
3 Paul 21 22
4 Agnor
I want to copy Ages from sheet 1 to sheet 2. So I would copy George, Paul, and Agnor's age, and ignore Jimmy. Which function should I use to copy data based on an existing value?
Is there something like:
foreach VAL in Sheet1
if(Sheet1.Name.EqualsIgnoreCase(Sheet2.Name))
{
Sheet2.Age = Sheet1.Age;
}
I looked this up, and a lot of people are saying to use VLookup, but I can't figure out how that would apply.
EDIT
I found a similar resolved question (No idea HOW I missed it) here: Compare and copy data between worksheets
However, I'm still a little shaky on how to implement this (I'm using Excel 2007).
vlookup would be the easiest way to go.
I will use cell B2 in sheet2 as the reference to try to explain the function
=VLOOKUP(A2,Sheet1!$A$2:$D$5,2,FALSE)
The first parameter is the data you are using for a lookup - you may want to change that to $A2 if you copy the formula around the sheet
The second parameter is where the data is that excel needs to find the value you referenced in the first parameter - use dollar signs. The data doesn't tend to move
The third parameter tells excel what info to return - the 2 means give me the 2nd piece of data
The last parameter tells excel if it can use a close match (FALSE for an exact match)
Now to follow Excel and see what it returns.....
First, it looks for George in the data (it knows it has to be an exact match from the fourth parameter)
Next, it finds the row George -- 22 -- Master -- 12 and gives the function the second value (22 in this case)

Resources