trying to expand vlookup to other cells without automatically changing values - excel

I am setting up a vlookup to pull product prices from another sheet within the workbook. The code works for the cell but when i try to expand or copy and past the code into the next row it automatically changes the data table_array value.
=VLOOKUP(B5,Prices!1:65536,3)
Within the code i want the first value, B5 to scale with the row it is in, however the second value needs to remain the same. How do i go about doing this? Also is there a way that i can get the cell to remain blank instead of displaying N/A if there isnt a valid part number?
Thanks for your help!

=VLOOKUP(B5,Prices!$1:$65536,3)
The $ lock the range.
For example.
$A1 will lock the column to A when the formulas is copied other
locations.
A$1 will lock the row
$A$1 will lock both the column and the row.

I can't comment because I do not have enough rep but this will fix user3716271 's formula:
=IF(ISERROR(VLOOKUP(B5,Prices!$1:$65536,3)),"", VLOOKUP(B5,Prices!$1:$65536,3))
The following formula should solve both problems as well, a little more compact and would use one less VLOOKUP():
=IFERROR(VLOOKUP(B5,Prices!$1:$65536,3), "")
As guitarthrower had said, the $ before the number is used to lock the range.

For the second part, an IF formula will work fine:
=IF(ISERROR(VLOOKUP(B5,Prices!1:65536,3)),"",VLOOKUP(B5,Prices!1:65536,3)),"")
And if I understand correctly the first part have you tried set an absolute value? Something like:
=IF(ISERROR(VLOOKUP(B$5,Prices!1:65536,3)),"",VLOOKUP(B5,Prices!1:65536,3)),"")

Related

Special character wanted which prevents an Excel formula from changing its reference when the referenced cell is moved

With the special character '$' I can prevent an Excel formula from changing its reference when the cell itself is copied (e.g '$A$1').
But is there also a special character that prevents an Excel formula from changing its reference when the referenced cell is moved?
Here's an example:
I have:
Now I move the cells 'A1:A3' down one row. So the formulas in the cells 'C1:C3' change:
But I don't want that the formulas in the cells 'C1:C3' change. They should remain unchanged:
Try formula:
=IF(INDEX(A:A,ROW(1:1))=INDEX(B:B,ROW(1:1)),"Same","Not same")
the formula always work, regardless of any column been delete besides columns A or B
If you always want to refer to A1, then you can't just use A1 as a reference, because, as you have seen, Excel will adjust that reference if rows are inserted above.
Instead, use Index(A:A,1) . That will always return the value from the first row of column A.
=if(index(A:A,1)=index(B:B,1),"same","not")
Edit after comment: If this does not suit your purpose, maybe you need to redesign your spreadsheet so that the position of things does not change all the time. This looks like you are adding new data at the top of a list.
Excel works from top to bottom and things will be a lot easier if new data is added at the bottom of a list. You can always use other Excel tools to change the sort order if you want to have the data sorted in reverse chronological order.
Use formula in C1:
=IF(INDEX(A:A,ROW(ZZ1))=INDEX(B:B,ROW(ZZ1)),"Same","Not same")
and copy down.

How do I use an array formula over a whole column or varying range?

I have a spreadsheet that I'm importing data into. I need to find the value within a column that is closest to zero. The column contains both positive and negative values, and the value closest to zero will be used in another formula. I've found an answer using an array formula, but it will only work for a fixed range (e.g. K2:K10), and the number of records imported into my sheet will vary each time I use it.
Here's what I have so far:
=INDEX(K:K,MATCH(MIN(ABS(K:K)),ABS(K:K),0))
Is there a way to apply an array formula over an entire column and just include non-zero cells other than the column title? Or possibly just cells with numerical values? Or is it possible to control the range that it applies to?
We can dynamically find the last cell in the range by using another INDEX/MATCH formula that is not an array:
=INDEX(K:K,MATCH(1E+99,K:K))
This will find the last cell that has a number in column K.
So we now use this as the last cell in the range:
=INDEX($K$2:INDEX(K:K,MATCH(1E+99,K:K)),MATCH(MIN(ABS($K$2:INDEX(K:K,MATCH(1E+99,K:K)))),ABS($K$2:INDEX(K:K,MATCH(1E+99,K:K))),0))
And now the formula is dynamic.
This formula is still an array formula and must be confirmed with Ctrl-Shift-Enter when exiting edit mode. If done correctly then Excel will put{} around the formula.
If as you pointed out there is a chance of deleting row 2 then all the K2 references will also be deleted.
In place of K2 we can use INDEX(K:K,2) It will now always look at the second row and will not error when row 2 is erased. So use this instead:
=INDEX(INDEX(K:K,2):INDEX(K:K,MATCH(1E+99,K:K)),MATCH(MIN(ABS(INDEX(K:K,2):INDE‌​X(K:K,MATCH(1E+99,K:K)))),ABS(INDEX(K:K,2):INDEX(K:K,MATCH(1E+99,K:K))),0))
There is nothing wrong with the Offset() function in small amounts, but it is a volatile function. Which means that it will calculate EVERY TIME excel calculate whether the data to which it is dependent has changed or not.
For the benefit of anyone reading this post, I ran into another issue and found a way around it. Scott Craner's answer above worked well until I ran a macro that I had for that sheet, which would delete certain rows. If row 2 got deleted, the formula would give a #REF error, because it was trying to call $K$2.
My solution was to replace $K$2 with
OFFSET(K1,1,0)
Therefore, the complete formula would be:
=INDEX(OFFSET(K1,1,0):INDEX(K:K,MATCH(1E+99,K:K)),MATCH(MIN(ABS(OFFSET(K1,1,0):INDEX(K:K,MATCH(1E+99,K:K)))),ABS(OFFSET(K1,1,0):INDEX(K:K,MATCH(1E+99,K:K))),0))
And as Scott mentioned, remember to hit Ctrl-Shift-Enter to execute the array formula.

Change variable horizontally in excel formula

I want to change a variable in an excel formula horizontally and maintain one variable constant.
O3/$C18, P3/$C18, Q3/$C18
I can keep the the bottom variable constant by using the $ symbol but when I want to extend the formula to additional cells, the top variable does not change horizontally, rather vertically.
Thank you for your help. Cheers
The dollar signs in excel "fix" the item to their right
$C18
means C will always be fixed, and 18 can change
C$18 means C can change, but 18 is always fixed.
$C$18 means C is fixed and 18 is fixed (ie always use C18 no matter what direction you drag the cell)
I dont fully understand what you want to do but hopefully the above will help
based on the comments below i think i understand what you mean
try a formula like this
=INDIRECT(ADDRESS(1,ROW()))/$C$18
here address takes the row and column, so row = 1 and column = which ever row you are on (so row1 = A, row2=B etc)
then indirect lets you use that as a reference point
Hope that works
If I understand you correctly, you want to copy your formula vertically, but have the columns update as if you were copying horizontally. For example, you want to copy =O3 to the cell below it as =P3.
For the top, consider the Offset() and Row() functions. Let's say that Cells A1,B1,C1 are 1,2, and 3. Try =OFFSET($A$1,0,ROW()-1). If you copy that formula vertically, the result will be 1, then 2, then 3.
So in your case, try =OFFSET($O$3,0,ROW()-1). It probably needs a little adjustment.
Here's another way to do this:
Start with the formula in this form:
=O$3/$P$18
Copy and paste it across so that you get:
=O$3/$P$18 =P$3/$P$18 =Q$3/$P$18
Copy the two formulas you pasted and select the cell below the first formula.
Then do a Paste Special / Transpose, which can be accessed by right-clicking the selected cell (that is, the one below the first formula that you entered) and then choosing the button that shows a little two-cell range flat and then upright.
Finish up by deleting the formulas in the cells you just copied from.

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 :)

Repeating a formula in a column in Google Docs

I have struggled for a long time with this. I need to enter the same formula in every cell of a column. However it changes the formula as it is dragged or copied. e.g. =J2 becomes =J3 =J4 etc. I need just =J2 in every cell.
Try =$J$2 instead of =J2
The $ symbol keeps the reference as-is, that is does not change it when it is dragged.
HTH.

Resources