I think you need to work through some of your logic and techniques.
First of all, I'd recommend using "Option Explicit" at the first of all code 
modules.This ensures that all variables are declared.(you can set this as 
default using Tools->Options and select "Require Variable Declaration)
With this option selected, you would have noticed that:
Set Start_Cost = Range(Inventory_Unit_Cost)
Set Start_Product = Range(Inventory_Products_Cost)
is treating Inventory_Unit_Cost and Inventory_Products_Cost as variables.VBA 
initializes them as "",so your code results in:Set Start_Cost = Range()
Set Start_Product = Range()
which isn't what you're looking for.
Using Option Explicit, VBA would inform you that these variables had not been 
declared and you would recognize that you need the quotes(")Set Start_Cost = 
Range("Inventory_Unit_Cost")
Set Start_Product = Range("Inventory_Products_Cost")
Secondly:Product_Code is being passed to the function and converted to a 
"String".from: Function FIFO(Product_Code As String
Now, in:If Product_Code = Start_Product(Counter, 1) Then
you're comparing Product_Code to the value in a cell.First of all, you're 
comparing the product code "1001" to the values in the COST?In the first loop, 
you're checking if "1001" = 536
Even if you were to check the product code to the values in the "Product_Code" 
column, you'd run into trouble.Simply because the product codes are numeric.so 
you're testing a string value against a numeric value:
"1001" = 1001 is FALSE.
to convert both values to strings, I often concatenate a "x" to the end of both:
if (Product_Code & "X" = Start_Product(Counter, 1).Value & "X") then
Do you use breakpoints and step through your code when debugging?
If not, you really ought to learn how.it is AMAZING for looking at run-time 
values as you step through your code to see what each line is doing!
Paul-----------------------------------------
“Do all the good you can,
By all the means you can,
In all the ways you can,
In all the places you can,
At all the times you can,
To all the people you can,
As long as ever you can.” - John Wesley
-----------------------------------------
 
      From: Shakeel Dhanani <dhanan...@gmail.com>
 To: MS EXCEL AND VBA MACROS <excel-macros@googlegroups.com> 
 Sent: Saturday, July 25, 2015 4:49 AM
 Subject: $$Excel-Macros$$ FIFO UDF not working
   
Dear All,

Please help, 

 i m trying to make FIFO Inventory Valuation UDF which is not working

-- 
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
https://www.facebook.com/discussexcel
 
FORUM RULES
 
1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.
 
NOTE : Don't ever post confidential data in a workbook. Forum owners and 
members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to excel-macros+unsubscr...@googlegroups.com.
To post to this group, send email to excel-macros@googlegroups.com.
Visit this group at http://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/d/optout.


   

-- 
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
https://www.facebook.com/discussexcel

FORUM RULES

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.

NOTE  : Don't ever post confidential data in a workbook. Forum owners and 
members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to excel-macros+unsubscr...@googlegroups.com.
To post to this group, send email to excel-macros@googlegroups.com.
Visit this group at http://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/d/optout.

Reply via email to