sspatriots
Well-known Member
- Joined
- Nov 22, 2011
- Messages
- 585
- Office Version
- 365
- Platform
- Windows
I have a workbook that will not allow the Undo feature to work. I'm guessing it has to do with having a workbook sheet change event in it. Anyone else have this issue? If so, is there a workaround? Or could this be due to another issue in the workbook, a setting or something?
Thanks SS
Thanks SS
VBA Code:
Dim oldValue As String
Dim oldAddress As String
Private Sub Workbook_Open()
Sheets("LogDetails").Visible = xlSheetVeryHidden
End Sub
Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
ShowHideLogSheet
'Target.Offset(1, 1).Select
Target.Offset(0, 0).Select
End Sub
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim sSheetName As String
'' add these defintiions
'Dim temparr(1 To 1, 1 To 9) As Variant
Dim temparr(1 To 1, 1 To 8) As Variant
'A, B, C, E, G, I, J, K & L column numbers
'A, B, E, G, I, K, L, M & N column numbers
'A, E, G, I, K, L, M & N column numbers
'colnos = Array(1, 2, 3, 5, 7, 9, 10, 11, 12)
'colnos = Array(1, 2, 5, 7, 9, 11, 12, 13, 14)
colnos = Array(1, 5, 7, 9, 11, 12, 13, 14)
'''''''''''''''''''''''''
'sSheetName = "2022"
sSheetName = ActiveSheet.Name
If ActiveSheet.Name <> "LogDetails" Then
Application.EnableEvents = False
'' this is not very good code, it could be much faster
Sheets("LogDetails").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = ActiveSheet.Name & " - " & Target.Address(0, 0)
Sheets("LogDetails").Range("A" & Rows.Count).End(xlUp).Offset(0, 1).Value = oldValue
Sheets("LogDetails").Range("A" & Rows.Count).End(xlUp).Offset(0, 2).Value = Target.Value
Sheets("LogDetails").Range("A" & Rows.Count).End(xlUp).Offset(0, 3).Value = Environ("username")
Sheets("LogDetails").Range("A" & Rows.Count).End(xlUp).Offset(0, 4).Value = Now
'Put back later, SPS, 03/09/22
Sheets("LogDetails").Hyperlinks.Add Anchor:=Sheets("LogDetails").Range("A" & Rows.Count).End(xlUp).Offset(0, 5), Address:="", SubAddress:="'" & sSheetName & "'!" & oldAddress, TextToDisplay:=oldAddress
Sheets("LogDetails").Columns("A:D").AutoFit
'' add this bit.
rowno = Target.Row
'inarr = Worksheets(sSheetName).Range(Cells(rowno, 1), Cells(rowno, 12))
inarr = Worksheets(sSheetName).Range(Cells(rowno, 1), Cells(rowno, 14))
'For I = 1 To 9
For i = 1 To 8
temparr(1, i) = inarr(1, colnos(i - 1))
Next i
With Sheets("LogDetails")
lastRow = .Cells(Rows.Count, "A").End(xlUp).Row
'.Range(.Cells(LastRow, 7), .Cells(LastRow, 15)) = temparr
.Range(.Cells(lastRow, 7), .Cells(lastRow, 14)) = temparr
End With
''''
Application.EnableEvents = True
End If
End Sub
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
'oldValue = Target.Value
If Target.Count > 1 Then Exit Sub
If Target.Count = 1 Then
oldValue = Target.Value
End If
oldAddress = Target.Address
End Sub