ReignEternal
New Member
- Joined
- Apr 11, 2021
- Messages
- 41
- Office Version
- 365
- Platform
- Windows
Hello,
I have been doing some searching and have been able to put this together but I am confused. From what i can read in the VBA below, I thought this should insert the data in A1:E1 but what is happening, is the data is being entered at the bottom of my table. I have a feeling I have butchered my attempt. I was aiming to be able to have any edits from any worksheet display the cell that was changed on a separate sheet, (the old data, the new data, the time it was changed, the date it was changed and the author that made the change). Now this is working to a degree. I have placed the VBA in each worksheet, when I tried to place it in the workbook any edit from any sheet was always going to a sheet I renamed. After doing some digging, I found out the sheet I renamed used to be Sheet1. I am assuming that I simply need to create a new sheet and replace where it says "Sheet1" to the new sheet # I create?
Here is a link to the workbook My workbook
I have been doing some searching and have been able to put this together but I am confused. From what i can read in the VBA below, I thought this should insert the data in A1:E1 but what is happening, is the data is being entered at the bottom of my table. I have a feeling I have butchered my attempt. I was aiming to be able to have any edits from any worksheet display the cell that was changed on a separate sheet, (the old data, the new data, the time it was changed, the date it was changed and the author that made the change). Now this is working to a degree. I have placed the VBA in each worksheet, when I tried to place it in the workbook any edit from any sheet was always going to a sheet I renamed. After doing some digging, I found out the sheet I renamed used to be Sheet1. I am assuming that I simply need to create a new sheet and replace where it says "Sheet1" to the new sheet # I create?
VBA Code:
Dim vOldVal 'Must be at top of module
Private Sub Worksheet_Change(ByVal Target As Range)
Dim bBold As Boolean
If Target.Cells.Count > 1 Then Exit Sub
On Error Resume Next
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Target.Interior.ColorIndex = 19
If IsEmpty(vOldVal) Then vOldVal = "Empty Cell"
bBold = Target.HasFormula
With Sheet1
If .Range("A1") = vbNullString Then
.Range("A1:E1") = Array("CELL CHANGED", "OLD VALUE", _
"NEW VALUE", "TIME OF CHANGE", "DATE OF CHANGE")
End If
With .Cells(.Rows.Count, 1).End(xlUp)(2, 1)
.Value = Target.Address
.Offset(0, 1) = vOldVal
With .Offset(0, 2)
If bBold = True Then
.ClearComments
End If
.Value = Target
.Font.Bold = bBold
End With
.Offset(0, 3) = Time
.Offset(0, 4) = Date
.Offset(0, 5) = ActiveWorkbook.BuiltinDocumentProperties("Last Author")
End With
.Cells.Columns.AutoFit
End With
vOldVal = vbNullString
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
On Error GoTo 0
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
vOldVal = Target
End Sub
Here is a link to the workbook My workbook