I am having issues using either Target.Select or Range(Target.Address) in my code. I have a code that after double clicking a cell, unprotects the sheet, and displays an inputbox for the user to enter an amount for a manual adjustment. This adjustment is pasted into another cell. Then, I protect the sheet, and I want to select the original cell that was double-clicked.
This works fine if I don't reprotect the sheet at the end, but if I do reprotect (even with .EnableSelection = xlUnlockedCells and .EnableSelection = xlLockedCells) the macro ends with the cell where the adjustment was made selected. This is extremely frustrating to me.
Just to clarify, what I want this code to to is this: if $I$9 is double-clicked, unprotect sheet, allow user to input amount, then paste that amount into $I$62, then reprotect sheet, and select cell $I$9.
Here is my code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
ActiveSheet.Unprotect
If Not Intersect(Target, Range("$A$3:$ZZ$51")) Is Nothing Then
Amount = InputBox("Enter amount:", "Amount", Target.Offset(53, 0).Value)
If StrPtr(Amount) = 0 Then
Application.SendKeys ("{ESC}")
ActiveSheet.Protect
Range(Target.Address).Select
Exit Sub
End If
If Cancel = True Then
Application.SendKeys ("{ESC}")
ActiveSheet.Protect
Range(Target.Address).Select
Exit Sub
Else
Target.Offset(53, 0) = Amount
End If
Application.SendKeys ("{ESC}")
End If
ActiveSheet.Protect
Range(Target.Address).Select
End Sub
Bookmarks