Worksheet Change code not running when you just delete data in cells.

K

KimberlyC

Hi,
I'm using the following code below (which is placed in the Workheet - Change
Module of the active worksheet) to create a list of codes on the previous
worksheet from the active worksheet. If a code is repeated numerous times on
the active worksheet, it only gets listed once on the previous worksheet.
It's working good, except when I press the delete key to remove codes..the
list on the previous worksheet does not change.. infact if I delete the
entire list on the active worksheet, there is no change on the previous
worksheet..the codes are still there..when they should be gone since I
deleted them from the active worksheet.

How can I get this code to run when the user just presses the delete key to
remove codes on the activeworksheet?
Using the delete key seems to not trigger the worksheet change code to run..


Private Sub Worksheet_Change(ByVal Target As Range)
Dim prevSheet As Worksheet

With Me

If .Index = 1 Then
MsgBox "No sheets to the left"
Set prevSheet = Worksheets("Adjustments")
Else
Set prevSheet = Worksheets(.Index - 1)
End If

.Unprotect Password:="test"

If Not Application.Intersect(Target, _
Range("A8:A1000")) Is Nothing Then
prevSheet.Range("A13:A100").ClearContents
prevSheet.Unprotect Password:="test"
gCopyUnique Range("A8:A1000"), prevSheet.Range("A13")
End If

.Unprotect Password:="test"

'Range("R16:R51").Select
prevSheet.Unprotect Password:="test"
prevSheet.Range("A13:A47").Sort , _
Key1:=prevSheet.Range("A13"), _
Order1:=xlAscending, _
Header:=xlGuess, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom
.Protect Password:="test", DrawingObjects:=True, _
Contents:=True, Scenarios:=True

End With
prevSheet.Protect Password:="test", DrawingObjects:=True, _
Contents:=True, Scenarios:=True
Application.ScreenUpdating = Ture

End Sub


Thanks in advance,
Kimberly
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top