I want to fill Column P with =Rcost() function to determine value based on the IF Thens in the code... Problem: How do you identify the row the function is working on? This gives me Value error.
Function Rcost(Mynum)
Dim Cell As Range
Dim R As Long
Dim Wks As Worksheet
Dim Listcost As String
Dim Repcost As String
Dim Specost As String
Dim Trancost As String
Dim Facter As String
Set Wks = ActiveSheet
Set Row = Mynum
Repcost = Wks.Cells(R, "Q")
Listcost = Wks.Cells(R, "O")
Specost = Wks.Cells(R, "R")
Trancost = Wks.Cells(R, "M")
If Wks.Cells(R, "O") = 0 Then
Facter = WorksheetFunction.Index(Worksheets("Mainframes").Range("L5:R6"), 1, Worksheets("Entry").Range("AJ1"))
ElseIf Round(Repcost / 0.48, 0) + Specost <= Listcost Then
Facter = WorksheetFunction.Index(Worksheets("Mainframes").Range("L5:R6"), 1, Worksheets("Entry").Range("AJ1"))
Else: Facter = WorksheetFunction.Index(Worksheets("Mainframes").Range("L5:R6"), 2, Worksheets("Entry").Range("AJ1"))
End If
If Wks.Cells(R, "S") = "Promo" Then
Rcost = Listcost
ElseIf Wks.Cells(R, "O") = 0 Then
Rcost = Round(Repcost / Facter, 0) + Specost
ElseIf Wks.Cells(R, "O") > 0 And Round(Repcost / Facter, 0) + Specost <= Listcost Then
Rcost = Round(Repcost / Facter, 0) + Specost
Else: Rcost = Listcost
End If
End Function
Bookmarks