2016-02-23

EXCEL/VBA - Write a record log into a sheet, appending at its bottom end


Public Function setLog( _
    SessionID As String _
    , functionName As String _
    , sql As String _
    , Optional userName As String _
) As Boolean

    ' Validate
    'Dim iris As New cIRIS
    If Not getSheetExistance("Log") Then
        setLog = False
        Exit Function
    End If

    ' Target Row
    Dim targetRow As Long
    targetRow = Cells(Rows.Count, 1).End(xlUp).Row + 1

    ' Log
    ThisWorkbook.Sheets("Log").Range("A1").Select
    Range("A" & CStr(targetRow)).Value = SessionID
    Range("B" & CStr(targetRow)).Value = Now()
    Range("C" & CStr(targetRow)).Value = sql
    Range("D" & CStr(targetRow)).Value = functionName
    Range("E" & CStr(targetRow)).Value = userName
    Range("F" & CStr(targetRow)).Formula = "=(B" & targetRow & "-B" & (targetRow - 1) & ")/0.0000115740741118013"
   
End Function

No comments:

Post a Comment