Computing.Net > Forums > Office Software > VLOOKUP Function

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

VLOOKUP Function

Reply to Message Icon

Name: alaska
Date: August 26, 2008 at 03:06:51 Pacific
OS: Windows XP
CPU/Ram: -
Product: -
Comment:

Hi,

I am attempting to use the VLOOKUP function, but can't see where the error is in the following.

I want whatever number is in N54 in worksheet 1 to be matched to the exact same number in column A of worksheet titled '7.SHAPIRO-WILK SIGNIFICANCE' and then the corresponding value across in column C on this worksheet inserted into the original cell in worksheet 1.

=VLOOKUP(N54,'7.SHAPIRO-WILK SIGNIFICANCE'!A3:C50,'7.SHAPIRO-WILK SIGNIFICANCE'!C3:C50,FALSE)

Appreciate any suggestions. Thanks



Sponsored Link
Ads by Google

Response Number 1
Name: DerbyDad03
Date: August 26, 2008 at 04:19:40 Pacific
Reply:

Look at the Help files for VLOOKUP and compare the construction of your formula to both the text description and the examples. Do it argument by argument.

I think you'll see a major difference.


0

Response Number 2
Name: alaska
Date: August 26, 2008 at 08:05:33 Pacific
Reply:

Thanks, quite an obvious error on my part - I need to be more carful !. So the correct formula is:

=VLOOKUP(N54,'7.SHAPIRO-WILK SIGNIFICANCE'!A3:C50,3,FALSE)

Now one final quick one is that if I wanted to look up the corresponding value to N54 on the worksheet 7, and then when the relevant value is identified in Column 1 (A), the function reads across the row and picks out the value closest to the value in Cell A55 on Worksheet 1. Is that do-able without delivng into VB or macros ?

Thanks Again


0

Response Number 3
Name: DerbyDad03
Date: August 26, 2008 at 10:37:49 Pacific
Reply:

1 - Now that you've got the formula right, I'll toss in another tip:

0 is equivalent to FALSE, but takes 4 less keystrokes.

2 - re: Is that do-able without delving into VB or macros ?

It's VBA (Visual Basic for Applications) and it's used to write macros. It's not one or the other.

3 - re: picks out the value closest to the value in Cell A55 on Worksheet 1

What if there is an exact match?

Closest without going over or closest without going under?

What if there is a tie? e.g. 4 and 6 are equidistant from 5.


0

Response Number 4
Name: alaska
Date: August 26, 2008 at 10:58:44 Pacific
Reply:

ok, points 1. and 2. noted.

Regarding point 3. If there is an exact match then it needs to
choose that value, otherwise the nearest. If there is tie, which
is possible but not as likely as you suggest given the values
are at three decimal places, then i would say the lower of the
values should be chosen as this would make for a more
conservative assessment, which suits the nature of what I am
attempting to put together.


0

Response Number 5
Name: DerbyDad03
Date: August 26, 2008 at 12:11:05 Pacific
Reply:

That's going to involve VBA in the form of a UDF (User Definded Function). A User Defined Function is a function that can be used in Excel but which calls some VBA code to determine the final value of the function.

If you paste the following code into a regular VBA module, you can use the UDF NearestNumber() in your worksheet by entering something like this in a cell:

=NearestNumber(A1:A20,C1)

This should find the value in A1:A20 that is closest to the value in C1.

I won't take credit for writing this, but I will take credit for finding it and incorporating it into the formula at the end of this post. ;-)


Function NearestNumber(varValue As Variant, rngRange As Range) As Variant
Dim sngDistance As Single
Dim varResult As Variant
Dim c As Range

sngDistance = 0

For Each c In rngRange
If c = rngRange.Cells(1, 1) Or Abs(c.Value - varValue) < sngDistance Then
sngDistance = Abs(c.Value - varValue)
varResult = c.Value
End If
Next

NearestNumber = varResult

End Function

So without thinking about this too deeply, here is how I would solve your overall issue:

1 - I would add a column to the end of the table where I have my data.

2 - I would use the NearestNumber UDF in that column so that that column would always contain the number from each row that is closest to the value in A55. Since it's a volitile function, the result will change as you change the number in A55 or in a given row, just like any Excel function.

3 - I would use the VLOOKUP function to return the value in that column. In other words, the table_array in the VLOOKUP function would include that column, and that column would be col_index_num.

e.g.

N54 contains Car
A55 contains 5.25
D1 contains =NearestNumber($A$55,B1:C1)
D2 contains =NearestNumber($A$55,B2:C2)
Etc.


=VLOOKUP(N54,A1:D4,4,0) will return 3 since that is the closest number to 5.25 in the row that contains Car.



A B C D

1 Bike 4 7 4 <- Result of UDF
2 Boat 5 6 5 <- Result of UDF
3 Car 3 8 3 <- Result of UDF
4 Plane 2 6 6 <- Result of UDF


0

Related Posts

See More



Response Number 6
Name: alaska
Date: August 27, 2008 at 05:02:19 Pacific
Reply:

Thanks for that I shall give it a go.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Problem with Adobe manage... Scroll bar in Word 2003



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Office Software Forum Home


Sponsored links

Ads by Google


Results for: VLOOKUP Function

VLOOKUP Function Excell www.computing.net/answers/office/vlookup-function-excell/3170.html

Excel Function (Vlookup) www.computing.net/answers/office/excel-function-vlookup/7310.html

Alternative to VLOOKUP? (Excel2k) www.computing.net/answers/office/alternative-to-vlookup-excel2k/633.html