Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Vlookup function

Hello,

I have the following code

Function Price(Code, Table)
Price = WorksheetFunction.VLookup(Code, Table, 18, False)
End Function

am using this function in order to get from the 18th column the price of a
specific product with Code. The codes of the different products are listed in
the 1st column. On the 1st column the codes of the different products can be
repeated many times.
With this vba code I am using I can get the price of the first listed
product. But I want to get the last.
Can someone please help me solve this problem?

Thank you in advance.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Vlookup function

Antonis,

Try this

Function Price(Code, Table)
Dim oCell As Range
Dim sFirst As String
Dim oLast As Range

With Table
Set oCell = .Find(Code)
If Not oCell Is Nothing Then
sFirst = oCell.Address
Do
Set oCell = .FindNext(oCell)
If Not oCell Is Nothing And oCell.Address < sFirst Then
Set oLast = oCell
End If
Loop While Not oCell Is Nothing And oCell.Address < sFirst
End If
End With
Price = oLast.Offset(0, 17).Value
End Function


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Antonis" wrote in message
...
Hello,

I have the following code

Function Price(Code, Table)
Price = WorksheetFunction.VLookup(Code, Table, 18, False)
End Function

am using this function in order to get from the 18th column the price of

a
specific product with Code. The codes of the different products are listed

in
the 1st column. On the 1st column the codes of the different products can

be
repeated many times.
With this vba code I am using I can get the price of the first listed
product. But I want to get the last.
Can someone please help me solve this problem?

Thank you in advance.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default Vlookup function

"Antonis" wrote in message
...
Hello,

I have the following code

Function Price(Code, Table)
Price = WorksheetFunction.VLookup(Code, Table, 18, False)
End Function

am using this function in order to get from the 18th column the price of a
specific product with Code. The codes of the different products are listed
in
the 1st column. On the 1st column the codes of the different products can
be
repeated many times.
With this vba code I am using I can get the price of the first listed
product. But I want to get the last.
Can someone please help me solve this problem?

Thank you in advance.


In a simple way:
------------------------------
Function Price(Code, Table)
Dim i As Long

For i = Table.Rows.Count To 1 Step -1
If Table(i, 1) = Code Then
Price = Table(i, 18)
Exit Function
End If
Next

End Function
-----------------------------

Ciao
Bruno


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default Vlookup function

I am only loudly thinking

introduce a helper column and type serials 1,2,3, etc
sort(DSESCENDING) the database acordings to this column
and now try (not tested)




"Bruno Campanini" wrote in message
...
"Antonis" wrote in message
...
Hello,

I have the following code

Function Price(Code, Table)
Price = WorksheetFunction.VLookup(Code, Table, 18, False)
End Function

am using this function in order to get from the 18th column the price of

a
specific product with Code. The codes of the different products are

listed
in
the 1st column. On the 1st column the codes of the different products

can
be
repeated many times.
With this vba code I am using I can get the price of the first listed
product. But I want to get the last.
Can someone please help me solve this problem?

Thank you in advance.


In a simple way:
------------------------------
Function Price(Code, Table)
Dim i As Long

For i = Table.Rows.Count To 1 Step -1
If Table(i, 1) = Code Then
Price = Table(i, 18)
Exit Function
End If
Next

End Function
-----------------------------

Ciao
Bruno




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to combine Combo Box function with Vlookup function KH Excel Worksheet Functions 2 April 5th 10 01:24 PM
Combine VLOOKUP and IF function so #NA isn't returned as a value from VLOOKUP buffgirl71 Excel Discussion (Misc queries) 12 November 14th 06 11:36 PM
HOW DO I NEST THE VLOOKUP FUNCTION WITH THE LEFT FUNCTION CHAIM Excel Worksheet Functions 1 July 27th 05 09:10 PM
how do I write a vlookup function within an iserror function so t. JBLeeds Excel Worksheet Functions 2 March 16th 05 10:30 AM
I want to use Vlookup function and AND function in a single formu. prakash Excel Worksheet Functions 3 January 25th 05 07:11 AM


All times are GMT +1. The time now is 04:05 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"