Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Using named range in vlookup

I an trying to create a function using a named range refering to another
sheet than the active sheet i am working on.

The problem i seem to have is if the named range is on the active sheet it
is woring fine, however if it refers to another sheet it returns a value of
"0". My situation is that i need to do a vlookup on a stock code and return a
cost value from a sheet called stock and the named range is also stock.

My cuurent sheet name is the same as my stock code that a an working on.

On using the vlookup in a normal subroutine to check if the stock code is in
the list it works fine. It is only in my function that it is not working
correct.

Here is the code for the function i have written so for.

Function matcostcalc(Stype, Item)

Dim StockCode As String
Dim Range1 As String
Dim lookup1 As String


StockCode = Item
lookup1 = Application.WorksheetFunction.VLookup(Item,
Range(Sheets("STOCK").Columns("A:a"), Sheets("STOCK").Columns("e:e")), 5,
False)


Application.Volatile True
'stockmaster

'calculate the cost for each product. depending on if it is bill of
material
'or manufactured item

Select Case Stype

Case "BILL"

matcostcalc = Application.WorksheetFunction.Sum(Range(Item))

Case "b/o"
'=VLOOKUP(C8,stock,5,FALSE)

matcostcalc = Application.WorksheetFunction.VLookup(Item,
Range(Sheets ("STOCK").Columns("A:a"), Sheets("STOCK").Columns("e:e")), 5,
False)

Case "labour"

matcostcalc = Application.WorksheetFunction.VLookup(Item,
Range(Sheets("STOCK").Columns("A:a"), Sheets("STOCK").Columns("e:e")), 5,
False)

End Select
End Function
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using named range in vlookup


I've never test this but for the range to work I think you can do lik
this:

StockCode = Item
with Sheets("STOCK")
lookup1 = Application.WorksheetFunction.VLookup(Item, _
.Range(.Columns("A:a"), .Columns("e:e")), 5,False)
end with

Best regards

--
hidek
-----------------------------------------------------------------------
hideki's Profile: http://www.excelforum.com/member.php...fo&userid=1890
View this thread: http://www.excelforum.com/showthread.php?threadid=40139

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
vlookup, concatenated named range patti Excel Worksheet Functions 4 March 14th 10 03:20 AM
VLOOKUP with a Named Range argument modernminstrel Excel Worksheet Functions 1 October 13th 08 04:11 PM
Vlookup in a named range tuph Excel Worksheet Functions 7 May 29th 06 02:23 AM
Vlookup in large named range KemS Excel Worksheet Functions 3 November 23rd 05 06:14 PM
Vlookup on named range kev Excel Programming 1 September 23rd 04 12:23 PM


All times are GMT +1. The time now is 11:52 PM.

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"