I want to return the function value as a paste special value if the function is false (like a hard coded answer). Can anyone help me please? I thought it was easier to use function instead of sub, because i have to do this to a fairly big data set.
Function produktion(d2, sum1, sum2)
Dim j As Integer
j = Application.Sum(sum1) - Application.Sum(sum2)
If d2 = Date Then
produktion = j
Else
'here hardcode the produktion = j forever like the paste special value
Thank you for your time!
A UDF cannot directly modify a worksheet, it can only return a value. There are work arounds that trigger code to execute outside the UDF call itself.
One such is to use
Evaluate
to call the code that modifies the sheet (another is to use worksheet events as Gary answered)