Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim LR As Long, NewVal As Variant, OldVal As Variant
If Sh.Name = "Log" Then Exit Sub
If Not Intersect(Target, Range("Data")) Is Nothing Then Exit Sub
Application.EnableEvents = False
NewVal = Target.Value
Application.Undo
OldVal = Target.Value
Target.Value = NewVal
If OldVal <> NewVal Then
With Sheets("Log")
LR = .Range("A" & Rows.Count).End(xlUp).Row
.Range("A" & LR + 1).Value = VBA.Environ("username") 'user
.Range("B" & LR + 1).Value = Now 'date and time
.Range("C" & LR + 1).Value = Sh.Name 'sheet
.Range("D" & LR + 1).Value = Target.Address(False, False) 'cell
.Range("E" & LR + 1).Value = OldVal 'previous value
.Range("F" & LR + 1).Value = Target.Value 'new value
End With
End If
Application.EnableEvents = True
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim NewRwHt As Single
Dim cWdth As Single, MrgeWdth As Single
Dim c As Range, cc As Range, c1 As Range
Dim ma As Range
Dim nextcell As Range
Set nextcell = ActiveCell(1)
Set c1 = Target.Cells(, 14)
With Target
If .MergeCells And .WrapText Then
With ActiveSheet
.Protect Password:="pw", AllowFormattingCells:=True, userinterfaceonly:=True
.EnableSelection = xllockedCells
End With
Set c = Target.Cells(1, 1)
r1 = Target.Row
cWdth = c.ColumnWidth
Set ma = c.MergeArea
For Each cc In ma.Cells
MrgeWdth = MrgeWdth + cc.ColumnWidth
Next
Application.ScreenUpdating = False
ma.MergeCells = False
c.ColumnWidth = MrgeWdth
c.EntireRow.AutoFit
NewRwHt = c.RowHeight + 1
c.ColumnWidth = cWdth
ma.MergeCells = True
ma.RowHeight = NewRwHt
cWdth = 0: MrgeWdth = 0
ma.Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 1
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
c1 = Target.Height
Row = ActiveCell.Row
Avalue = Range("AA" & Row).Value
If Target.Cells.Height < Avalue Then
Rows(r1).RowHeight = Avalue
End If
Selection.Locked = False
Selection.FormulaHidden = False
nextcell.Select
Else
nextcell.Select
End If
End With
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim NewRwHt As Single
Dim cWdth As Single, MrgeWdth As Single
Dim c As Range, cc As Range, c1 As Range
Dim ma As Range
Dim nextcell As Range
Application.EnableEvents = False
Set nextcell = ActiveCell(1)
Set c1 = Target.Cells(, 14)
With Target
If .MergeCells And .WrapText Then
With ActiveSheet
.Protect Password:="pw", AllowFormattingCells:=True, userinterfaceonly:=True
.EnableSelection = xllockedCells
End With
Set c = Target.Cells(1, 1)
r1 = Target.Row
cWdth = c.ColumnWidth
Set ma = c.MergeArea
For Each cc In ma.Cells
MrgeWdth = MrgeWdth + cc.ColumnWidth
Next
Application.ScreenUpdating = False
ma.MergeCells = False
c.ColumnWidth = MrgeWdth
c.EntireRow.AutoFit
NewRwHt = c.RowHeight + 1
c.ColumnWidth = cWdth
ma.MergeCells = True
ma.RowHeight = NewRwHt
cWdth = 0: MrgeWdth = 0
ma.Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 1
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
c1 = Target.Height
Row = ActiveCell.Row
Avalue = Range("AA" & Row).Value
If Target.Cells.Height < Avalue Then
Rows(r1).RowHeight = Avalue
End If
Selection.Locked = False
Selection.FormulaHidden = False
nextcell.Select
Else
nextcell.Select
End If
End With
Application.EnableEvents = True
End Sub