badly need help on how to code this on VBA

41 Views Asked by At

badly need help on how to code this on VBA... excel column C: date borrowed, col E: status, col F: date returned. i need to automatically fill the status (Out or In). Out if col C is filled but col F is blank. then it will automatically update to "In" if col F is filled.

i have tried to use the isempty but cant seem to link it when the value of date borrowed is already filled.

1

There are 1 best solutions below

3
Ike On

You can use this formula:

= IF(C2<>"",IF(F2="","Out","In"),"")

If Date borrowed (C) is not empty, then the formula checks for Date returned (F): if empty then "out" else "in".

A VBA solution could look like this:

Public Function getStatus(dateBorrowed As Date, dateReturned As Date) As String
If dateBorrowed > 0 Then
    If dateReturned > 0 Then
        getStatus = "In"
    Else
        getStatus = "Out"
    End If
End If
End Function

You would call it getStatus(activesheet.range("C2"), activesheet.range("F2"))