I am trying to make a function where, based on an article code, the funciton looks in a different sheet with matching codes and takes the right discount (5 columns to the right of the cell with the code).
Then I would like to return a specific value when the discount is set as "standaard".
Everything seems fine in the immediate window, but when I enter the formula in a cell, It returns #VALUE.
Here is the code:
Then I would like to return a specific value when the discount is set as "standaard".
Everything seems fine in the immediate window, but when I enter the formula in a cell, It returns #VALUE.
Here is the code:
VBA Code:
Function Discount()
Application.Volatile True
Dim c As Variant
Dim cl As Range
Dim r As Integer
Dim a As String
r = ActiveCell.Row
a = Sheets(1).Cells(r, 3).Value
Sheets(2).Activate
With Sheets(2).Range("B3:B40000")
Set cl = Sheets(2).Range("B2:B10000").Find(a, LookAt:=xlWhole)
If Not cl Is Nothing Then
cl.Select
End If
End With
If ActiveCell.Offset(0, 5).Value = "standaard" Then
c = 1
End If
Discount = c
End Function