I have created a sheet that logs all the changes made to a pretty involved database (seperate file) I created. When any change is made to the database's databank, it is also copied to this file along with the time the change was made.
As part of this, I want the user to be able to (if they make a mistake in a newer revision), revert back to an old one by performing a couple of actions. I decided to do this by creating a drop down data validated list next to every record. When you select "Restore to Here", it brings up UserForm1.
My problem is that no matter what I do I, I get something saying that Excel has encountered an error and needs to close after I close out the userform(which has no code behind it right now). When I restart the recovered file has taken off my data validated lists. I have tried placing the section of code that brings up the userbox in both the sheet and in a module. I have also tried working around it by running part of the code, deleting the data validation, and then reapplying the data validation(never gets that far). Nothing seems to work. I thought maybe it has to do with what the UserForm has on it, but no matter what I still get the same error.
Any ideas? I really want to use data validated lists and have searched and searched and can't find any solution. I am self-taught with VBA, but I've constantly been getting better.
Here's my code.
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
Dim LastCellHider As Range
Dim Hider As Range
Cells.EntireRow.Hidden = False
Set LastCellHider = Worksheets("Changelog").Range("C65536").End(xlUp)
Set Hider = Range("C3", LastCellHider)
For Each Cell In Hider.Cells
If Cell.Value = "HIDE" Then
Cell.EntireRow.Hidden = True
End If
Next Cell
If Range("B1").Value = "" Then
Range("D1:I1").Interior.ColorIndex = 1
Else
Range("D1:I1").Interior.ColorIndex = 2
End If
Call Restorer
If Range("C1").Value = 0 Then
Exit Sub
Else
Application.EnableEvents = False
Range("J1").Value = Cells.Find(What:=Range("B1"), After:=Range("E2"), LookIn:=xlValues, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Offset(0, -3)
Range("K1").Value = Cells.Find(What:=Range("B1"), After:=Range("D65536"), LookIn:=xlValues, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False _
, SearchFormat:=False).Offset(0, -3)
Range("L1").Value = Cells.Find(What:=Range("B1"), After:=Range("D65536"), LookIn:=xlValues, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False _
, SearchFormat:=False).Offset(0, 92)
Application.EnableEvents = True
Rows("1").AutoFit
End If
End Sub
Sub Restorer()
Dim LastCellRestore As Range
Dim Restore As Range
Set LastCellRestore = Worksheets("Changelog").Range("D65536").End(xlUp)'finds lower bound of range
Set Restore = Range("D3", LastCellRestore)
For Each Cell In Restore.Cells
If Cell.Value = "Restore to Here" Then
Cell.ClearContents
Range("O1").Value = Cell.Offset(0, 1).Value 'Record Number
Range("P1").Value = Cell.Offset(0, -2).Value 'Time Record was edited
'On the sheet, cells "O1" and "P1" are then Concatenated with other text to Q1, which is the text of the locked textbox on the UserForm.
UserForm1.Show'Opens fine
End If
Next Cell
End Sub
As part of this, I want the user to be able to (if they make a mistake in a newer revision), revert back to an old one by performing a couple of actions. I decided to do this by creating a drop down data validated list next to every record. When you select "Restore to Here", it brings up UserForm1.
My problem is that no matter what I do I, I get something saying that Excel has encountered an error and needs to close after I close out the userform(which has no code behind it right now). When I restart the recovered file has taken off my data validated lists. I have tried placing the section of code that brings up the userbox in both the sheet and in a module. I have also tried working around it by running part of the code, deleting the data validation, and then reapplying the data validation(never gets that far). Nothing seems to work. I thought maybe it has to do with what the UserForm has on it, but no matter what I still get the same error.
Any ideas? I really want to use data validated lists and have searched and searched and can't find any solution. I am self-taught with VBA, but I've constantly been getting better.
Here's my code.
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
Dim LastCellHider As Range
Dim Hider As Range
Cells.EntireRow.Hidden = False
Set LastCellHider = Worksheets("Changelog").Range("C65536").End(xlUp)
Set Hider = Range("C3", LastCellHider)
For Each Cell In Hider.Cells
If Cell.Value = "HIDE" Then
Cell.EntireRow.Hidden = True
End If
Next Cell
If Range("B1").Value = "" Then
Range("D1:I1").Interior.ColorIndex = 1
Else
Range("D1:I1").Interior.ColorIndex = 2
End If
Call Restorer
If Range("C1").Value = 0 Then
Exit Sub
Else
Application.EnableEvents = False
Range("J1").Value = Cells.Find(What:=Range("B1"), After:=Range("E2"), LookIn:=xlValues, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Offset(0, -3)
Range("K1").Value = Cells.Find(What:=Range("B1"), After:=Range("D65536"), LookIn:=xlValues, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False _
, SearchFormat:=False).Offset(0, -3)
Range("L1").Value = Cells.Find(What:=Range("B1"), After:=Range("D65536"), LookIn:=xlValues, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False _
, SearchFormat:=False).Offset(0, 92)
Application.EnableEvents = True
Rows("1").AutoFit
End If
End Sub
Sub Restorer()
Dim LastCellRestore As Range
Dim Restore As Range
Set LastCellRestore = Worksheets("Changelog").Range("D65536").End(xlUp)'finds lower bound of range
Set Restore = Range("D3", LastCellRestore)
For Each Cell In Restore.Cells
If Cell.Value = "Restore to Here" Then
Cell.ClearContents
Range("O1").Value = Cell.Offset(0, 1).Value 'Record Number
Range("P1").Value = Cell.Offset(0, -2).Value 'Time Record was edited
'On the sheet, cells "O1" and "P1" are then Concatenated with other text to Q1, which is the text of the locked textbox on the UserForm.
UserForm1.Show'Opens fine
End If
Next Cell
End Sub