Event Log VBA

ExcelGiu21

New Member
Joined
Jul 8, 2021
Messages
1
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello, I am using an online translator.

I have in VBA "EVENTLog"

I have a Table that goes from A to G

A = Author
B = Sheet Name
C = Line
D = Entered value
E = Old Value
F = current value
G = Date / Time

the information comes from the sheet "sheet1"

In "Sheet1" I wrote "Name" in D2

the VBA returns Cell C2 and D2 in the "Eventlog" sheet

how to return C1 and D2, or, F1 and G2 or, if I write in D3 returns C1 and D3?

Could you help me?

this is my VBA CODE :
VBA Code:
Private Sub Workbook_SheetChange (ByVal sheet As Object, ByVal target As Range)
Dim before () As Variant, after () As Variant
On Error GoTo end:

    If sheet.Name = "Journal" Then Exit Sub
    If target.Columns.Count = Columns.Count Or target.Rows.Count = Rows.Count Then
        Application.EnableEvents = False
            Application.Undo
        Application.EnableEvents = True
        MsgBox "Cannot act on a full row or column!"
        Exit Sub
    End If
   
    Application.EnableEvents = False
    ReDim before (1 TB target.Rows.Count, 1 TB target.Columns.Count)
    ReDim after (1 TB target.Rows.Count, 1 TB target.Columns.Count)
    Application.Undo
    For Lig = 1 To UBound (before)
        For col = 1 To UBound (before, 2)
            before (Lig, col) = target.Cells (1, 1) .Offset (Lig - 1, col - 1) .FormulaLocal
        Next
    Next
    Application.Undo
    For Lig = 1 To UBound (after)
        For col = 1 To UBound (after, 2)
            after (Lig, col) = target.Cells (1, 1) .Offset (Lig - 1, col - 1) .FormulaLocal
        Next
    Next
   
    For Lig = 1 TB target.Rows.Count
        For col = 1 TB target.Columns.Count
            If before (Lig, col) <> after (Lig, col) Then
                With Sheets ("Journal"). ListObjects (1)
                    .ListRows.Add
                    i = .ListRows.Count
                    With .DataBodyRange
                        .Cells (i, 7) = Now
                        .Cells (i, 2) = sheet.Name
                        .Cells (i, 4) = target.Cells (1, 1) .Offset (Lig - 1, col - 1)
                        .Cells (i, 3) = target.Cells (1, 1) .Offset (Lig - 1, premierecol - 1)
                        .Cells (i, 5) = "" & before (Lig, col)
                        .Cells (i, 6) = "" & after (Lig, col)
                        .Cells (i, 1) = Environ ("username")
                    End With
                End With
            End If
        Next
    Next
       
end:
    Application.EnableEvents = True
    If Err Then MsgBox "Error #" & Err.Number & "!"
   
End Sub

thx.
 
Last edited by a moderator:

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Forum statistics

Threads
1,214,606
Messages
6,120,478
Members
448,967
Latest member
visheshkotha

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top