Pull data using VBA, Vlookup or Index Matching - excel

Here is my question. I have tried to use Vlookup and receive an #NA and then I have tried to use Index Matching and the formula breaks and the returns are not all present. I receive some 0's and some #REF!'s in the column of my formula.
This is what I am trying to do. I have workbook with 2 work sheets. The first worksheet called 'brazil' is where I have written my formula in the column D.
Now, what I am trying to do is match up the email address from worksheet 'brazil email' and the worksheet from the 'brazil' and then pull the information from the cell in the 'brazil' worksheet a column that matches with the email from the formula.
The snippet shows the formula works in row 3 column D and returns the information from column A(employee), but breaks after a few rows and works intermittently.
Current my formula looks like this: =INDEX(A2:A34, MATCH(C2, 'Brazil email'!$A$2:$A48, 0))
Here is the snippet of the other worksheet: enter image description here
If you have any ideas on what could be causing the breakdown of my formula, that would be great.
I am willing to share a sample of the spreadsheet with you if needed. Thanks for any help. :)
Any other methods, like an alternate vlookup or vba would be great. :)
UPDATE 3/15:
I was able to update my formula and locked it down as per the great advice given on the below comment. :)
This is the latest update. I am still receiving #REF! on some of my cells. I copied and pasted in case there was a space and verified that the column is set to general and not text.
What could possibly be giving me the #REF! when it should be the data from the matched and index cell. I see the other rows worked but for some reason some of the cells on column D didn't update with the data from column A.
Please assist since I have 25,000 lines of this I have to sort through and trying to work smarter not harder. :)
I have removed the original snippet since the update given has corrected some of the errors. Here is the latest image with the current #REF!, Please assist: enter image description here

Looking at your formula, it seems that the first parameter should be locked:
=INDEX($A$2:$A$34, MATCH(C2, 'Brazil email'!$A$2:$A$48, 0))
When you copy your formula down, Excel will shift that first bit out of bounds.
UPDATE:
The #REF! usually comes from copying/pasting formulas or deleting/moving referenced data.
What I can think here is to make sure to put the working formula in the top cell and paste all the way down.
Also important: Added another lock to the formula (didn't see it before), on the referenced range inside the MATCH section.

Related

Excel problem for beginners: #REF! Error When referenced Row is deleted or Added

I have data in column A which is copied in another random location. The copied data could also be in column B-Z, AA... Etc, Or alternatively could be on a new sheet by setting the column =Sheet1!A1 for example.
In the attached image I initially had a,b,c...through to f.
In this example,data is copied in the same column just further down by entering at A10 =A1 and copying down as required.
When what was A5 is deleted as a row to remove 'e' you can see that A14 now has the #REF! Error. This is strange to me because although the row is deleted the data has shifted up one. so A14=A5 which previously returned 'e' should now return 'f' but instead returns the error. Initially I thought that this is because the data is in the same column but the same error is returned if on another sheet for example If I set A1=Sheet1!A1 and then delete a row on sheet1.
If you drag down the copying formula again the error is corrected But surely this can be made to happen automatically? Especially if dealing with large amounts of data.
Surprisingly this error doesn't seem to have an obvious solution posted online. I wanted to create this post for anyone to suggest feasible solutions for those starting out with excel (including myself).
If you use a general formula like =A5 then you will face this issue. Excel is not built to handle this internally.
The best way to avoid this error is to use the OFFSET function. This function is dynamic so it will update when cells are added or deleted.
Hope this fixes your problem.
Setting the column to a range instead of =A1 and drag down, this seems to solve all problems.
e.g. =A1:A7 will return a-h but also if a row is then deleted/inserted the formula adapts accordingly.
Avoid #REF
The best way I found (so far) is the following formula in cell A10:
=IFERROR(INDEX(A$1:A$9,ROW(A10)-ROW(A$10)+1),"")
You can delete any or all except two rows. Two rows are necessary for the range A$1:A$9 to work. If you would leave only one row, the range would be A$1:A$1 and could not be increased anymore.
You can insert new rows before the last row (9). If you insert a row after the last row (9), it will not be affected by the formula.

Look up multiple values in a list and sort them in a new sheet

I have a data sheet that contains 9 columns corresponding to a name. But the names are repeated. So I want to create new sheets for all names and filter their data from the data sheet. The sheets must be updated when any changes are made on the data sheet.
I tried VLOOKUP but had some various problems, and it didn't work well for me. I've found a way that may help, but it's prepared for Excel. ( https://fiveminutelessons.com/learn-microsoft-excel/use-index-lookup-multiple-values-list )
In OpenOffice ROW(1:1) doesn't give a result. Dragging as an array also doesn't change the cells in the formula. So are there any alternative ways to solve this problem? (OpenOffice solutions are preferred).
The example from the link in the question almost works in LibreOffice. To fix it, instead of ROW(1:1), use ROW($A$1:$A$6).
I am not sure what ROW(1:1) does in Excel, and I could not find an explanation online. In Calc, ROW($A$1:$A$6) returns an array of 1 column x 6 rows: {1;2;3;4;5;6}.
So here is the full formula using the example.
=IF(ISERROR(INDEX($A$2:$C$7,SMALL(IF($A$2:$A$7=$A$9,ROW($A$2:$A$7)),ROW($A$1:$A$6))-1,3)),"",INDEX($A$2:$C$7,SMALL(IF($A$2:$A$7=$A$9,ROW($A$2:$A$7)),ROW($A$1:$A$6))-1,3))
Be sure to enter it as an array formula with Ctrl+Shift+Enter

Copying cells from one worksheet to another if a column matches a value

I'm trying to use formula to copy data from one worksheet to another where a column matches a certain value.
To be more specific, I want Working!A2:E100 to contain Data!A2:E100 but only for those rows where Data!C2:100 contains the value "Fixed".
Doing this with leaving blank rows is simple, I just create the formula:
=IF(Data!$C2="Fixed", Data!A2, "")
And copy that formula across all the cells.
But then I thought I'd get clever and have it not copy across blank lines, and entered a maze of unclear excel tutorials and vague error messages.
I've created this formula:
=INDEX(Data!A2:Data!A200, MATCH("Fixed", Data!$C$1:Data!$C$200, 0))
And entered it as an array formula using ctrl shift enter.
However all I get is the contents of Data!A2 repeated over and over in every cell of my spreadsheet.
Does anyone need to know what I need to do to make this work?
This is my attempt at a local prototype following the example in BruceWayne's answer, the results are visible:
As you can see "Row 2" just appears repeatedly in the result column. Excel doesn't seem to have an easy way to see what version it is any more but this seems to be a pretty recent one, it's got the ribbon with the file menu and all menu headings are capitalized.
Here's a formula you can use (note: enter this as an array):
=IFERROR(INDEX(A$1:A$200,SMALL(IF(C$1:C$200="Fixed",ROW(A$1:A$200)-ROW(A$1)+1),ROWS(A$1:A1))),"")
You may need to tweak the ranges, I think I got them to match yours, but again, probably need to tweak. You can then drag this down, and it'll fill in with the values from column A, skipping any blanks.
Edit: Here's a screenshot to (hopefully) help show what I did:
You can edit the ranges, naturally, to be over two sheets.
To clarify, A$1:A$200 is the range of what you want to return (the index). C$1:C$200 is the range that holds "Fixed".

using hyperlink in a vlookup function

very new to this and only just managed the vlookup, anyway,
i have a workbook which contains two Sheets. On Sheet1 I have the following formula (=VLOOKUP(CZ54,Sheet2!$A$1:$Y$176,3,FALSE)) which displays the ID number from Sheet2. This works correctly but how do I get to appear as a hyperlink so once clicked it goes to the specific cell it got from the vloopkup on Sheet2?
I have tried =HYPERLINK(VLOOKUP(CZ54,Sheet2!$A$1:$Y$176,3,FALSE) but I get the error "Cannot get the specified file".
I would be grateful if anyone can point me in the right direction, thank you.
Ok... this looks crazy. This should work for you. I tested it on my machine and it works:
=HYPERLINK(MID(CELL("filename"),SEARCH("[",CELL("filename")), SEARCH("]",CELL("filename"))-SEARCH("[",CELL("filename"))+1) & ADDRESS(MATCH(CZ54,Sheet2!$A$1:$A$176),3,,,"sheet2"),VLOOKUP(CZ54,Sheet2!$A$1:$Y$176,3,FALSE))
Let's break it up a little just to explain some of the parts:
MID(CELL("filename"),SEARCH("[",CELL("filename")), SEARCH("]",CELL("filename"))-SEARCH("[",CELL("filename"))+1)
Returns a string [currentFileName], which is the required format for a hyperlink within a workbook.
MATCH(CZ54,Sheet2!$A$1:$A$176),3,,,"sheet2")
Returns the row number of value of CZ54 in the first column of your VLookup range.
ADDRESS(MATCH(CZ54,Sheet2!$A$1:$A$176),3,,,"sheet2")
Returns the address of the row found, and the column(3, from your vlookup) in sheet2.
So combined:
MID(CELL("filename"),SEARCH("[",CELL("filename")), SEARCH("]",CELL("filename"))-SEARCH("[",CELL("filename"))+1) & ADDRESS(MATCH(CZ54,Sheet2!$A$1:$A$176),3,,,"sheet2")
Returns the actual address for the hyperlink, which is the first parameter of the HYPERLINK formula.
The second parameter is the Vlookup you provided, and voilĂ .
Edit: A warning if anyone tries to use this for a similar issue, if the lookup_array used in Match or Vlookup does not start with Row 1 or column 1 respectively, you will need to offset the values sent to ADDRESS with a +(starting row or column - 1). Example: Match(CZ54,$A$2:$A$176)+1 instead of MATCH(CZ54,Sheet2!$A$1:$A$176).
Here's a more compact version of Daniel's formula.
Using Hyperlink to link to another sheet in the same workbook, you can replace the reference to the workbook name with #.
Eg =HYPERLINK("#Sheet2!$C$10","Click Here")
So, applying this you get
=HYPERLINK("#"&ADDRESS(MATCH(E21,Sheet2!$A$1:$A$176),3,,,"sheet2"),VLOOKUP(E21,Sheet2!$A$1:$Y$176,3,FALSE))
HYPERLINK is looking for text so if you were to do something like
=HYPERLINK(left(VLOOKUP(CZ54,Sheet2!$A$1:$Y$176,3,FALSE),255))
it should return a usable hyperlink

How to look up information based off a single cell? In Excel

I've been working on VBA for so long I forgot how to do this...using formulas.
I have a cell that has a descriptor in it, in this case K1122121. The cell next to it, will be the description. On another sheet I have a list of parts, I need to look up said part number on sheet 2, and place the description next to the part it's looking up.
I know it's possible, I just forget how.
So to recap.
Sheet one has two cells, the first is a part number, the 2nd next to it, is where the formula is going, in this cell will produce the description to said part number.
Sheet two has part and description side by side. I need to reference the part number and find the description.
Once the description is found, place said description in the description field in sheet one.
Thanks for the help.
Here is a link of what I am working on. https://dl.dropbox.com/u/3327208/Excel/PAERTO.xlsm
It's called VLOOKUP and you call it like this:
=VLOOKUP(A1,Sheet2!A:B,2,FALSE)
Where:
A1 is the cell with the part number in sheet1
Sheet2 the sheet where the data is located (descriptor / description)
A:B is the range in sheet2 where the data is located
2 because what you are looking for is in the second column
FALSE to only get a value for exact matches - if no exact match is found, it will show an error
EDIT
Looking at your workbook, I would personally insert a new column in the jobs list (say between D and E) with a formula that only keeps the first word only - formula in E3:
=IF(ISERROR(FIND(" ",D3)),D3,LEFT(D3,FIND(" ",D3)-1))
Then the formula in the PAERTO sheet then becomes - formula in D20:
=VLOOKUP($E20,'Jobs List'!$E:$F,2,FALSE)
in the example you provided, I get a result for lines 20, 22 and 24, and an error on the other lines.
I can get a result if I use this formula:
=VLOOKUP(E20&" Rev"&F20,'Jobs List'!D:E,2,0)
However you need to change cell F20 to 4.
As long as part number and "Rev" are consistent between sheets, this formula should work.
Note that only cells D20 and D24 return values. The other part numbers don't exist on the other sheet, so regardless of what formula is used you will not see a return value.
With your part number in A1, in B1 the formula =VLOOKUP(A1,Sheet2!A:B,2,FALSE) will find the description
If you are on Excel 2003 or earlier, you will have to change Sheet2!A:B to be a full reference like Sheet2!A2:B2000
The answer was a little more complex than I was hoping, but I ended up using this as an answer. It may not be the most simplistic, or elegant, but it works.
=IF(E20=0,VLOOKUP("*"&E20&"*",'Jobs List'!D:E,2,FALSE),VLOOKUP("*"&E20&"*",'JL Archive'!D:E,2,FALSE))
I used the "*" to make it so that it utilized wild cards, something I never thought of using... but it works. I put the wildcard usage in front and behind so just in case any cells may have something more than the required text in the front of the part or behind it.
I hope this helps people. The original use for this was so I can use the formula can be used from another workbook, but as we all know this can be used anywhere. Enjoy :)

Resources