• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

getting error when using function procedue to get values in a macro

abhi1687

New Member
Hi All

i am trying to get values into a macro through function procedure but getting run time error 1004 "Application defined or object defined error" below is code i am using:
Code:
Range("K2:K" & lrd).FormulaR1C1 = "=LP(RC[-7])]"
here LP is the function name. i am using same function procedure as a formula in excel and it works fine. any ideas to solve this issue would be great help
thanks
 
do you know what the value of lrd is when it throws the error?

Can you post the code for the function LP?
 
lrd value is 2601 below is the code for function procedure, but this function procedure i am using as a formula in excel from long time and it works fine

Code:
Function LP(cel As Date)
 
Dim basedate As Date, fd As Integer, mn As Integer, yr As Integer, currentlp As Date, c As String, c1 As String, f As String
 
fd = Day(Now())
mn = Month(Now())
yr = Year(Now())
basedate = Int(Now()) - fd + 1
Select Case fd
    Case Is < 15
        clp = basedate
    Case Is >= 15
        clp = DateAdd("m", 1, basedate)
End Select
 
c = "CTR"
c1 = "CTR+1"
f = "FTR"
 
Select Case cel
    Case Is <= clp
        LP = c
    Case Is = DateAdd("m", 1, clp)
        LP = c1
    Case Is > DateAdd("m", 1, clp)
        LP = f
End Select
 
End Function
 
Back
Top