I am trying to create a function that will calculate the Total quantity of a product with number "pn001" and minus the sum in another sheet, the answer should be displayed in sheet where the function is called
Function salio() As Long
    Dim Sumact As Range
    Dim Sumact1 As Range
    Dim Remain As Long
    Dim RR As Long
    Dim R As Long
    Set Sumact = Sheets(1).Range("A1")
    Set Sumact1 = Sheets("SALES").Range("A1")
    Sheets("STOCK-OUT").Select
    Sumact = Application.SumIf(Range("C3:C5"), "pn001", Range("E3:E5"))
    RR = CLng(Sumact)
    Sheets("SALES").Select
    Sumact1 = Application.SumIf(Range("D2:D5"), "pn001", Range("F2:F5"))
    Remain = CLng(Sumact1)
    R = RR - Remain
    salio = R
End Function
All I get is the #VALUE! error when I attempt to use this on a worksheet.
 
    