Advertisement
julianmaeusling

ChangelogVBA

Jun 3rd, 2024 (edited)
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VisualBasic 1.68 KB | Source Code | 0 0
  1. Private ProtocolTable As Worksheet
  2. Private OriginalValue As Variant
  3. Private TargetTable As Worksheet
  4.  
  5. Private Sub Workbook_Open()
  6.     Dim ws As Worksheet
  7.     On Error Resume Next
  8.     Set ProtocolTable = ThisWorkbook.Sheets("Changelog")
  9.  
  10.     If ProtocolTable Is Nothing Then
  11.         Set ProtocolTable = ThisWorkbook.Sheets.Add
  12.         ProtocolTable.Name = "Changelog"
  13.         ProtocolTable.Range("A1:E1").Value = Array("Datum/Uhrzeit", "Tabelle", "Zelle", "Ursprünglicher Wert", "Neuer Wert")
  14.     End If
  15.  
  16.     On Error GoTo 0
  17.  
  18.     ' Hier die gewünschte Tabelle festlegen
  19.    Set TargetTable = ThisWorkbook.Sheets("Deine Tabelle")
  20.  
  21.     AddChangeEventHandler TargetTable
  22.  
  23. End Sub
  24.  
  25. Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
  26.     If ProtocolTable Is Nothing Then
  27.         Set ProtocolTable = ThisWorkbook.Sheets("Changelog")
  28.     End If
  29.  
  30.     If Sh Is TargetTable Then
  31.         Dim ProtokollZeile As Long
  32.         ProtokollZeile = ProtocolTable.Cells(ProtocolTable.Rows.Count, 1).End(xlUp).Row + 1
  33.         ProtocolTable.Cells(ProtokollZeile, 1).Value = Now
  34.         ProtocolTable.Cells(ProtokollZeile, 2).Value = Sh.Name
  35.         ProtocolTable.Cells(ProtokollZeile, 3).Value = Target.Address(False, False)
  36.         ProtocolTable.Cells(ProtokollZeile, 4).Value = OriginalValue
  37.         ProtocolTable.Cells(ProtokollZeile, 5).Value = Target.Value
  38.     End If
  39.  
  40. End Sub
  41.  
  42. Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
  43.     If Target.Count = 1 Then
  44.         OriginalValue = Target.Value
  45.     End If
  46.  
  47. End Sub
  48.  
  49. Private Sub AddChangeEventHandler(ByVal ws As Worksheet)
  50.     ' Keine zusätzliche Aktion erforderlich
  51. End Sub
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement