Tracking Deleted Row and Insertion Code

centaur63

New Member
Joined
Aug 31, 2006
Messages
42
The below code is supposed to track just the deletion of rows and columns. I want it to track the insertion of any new cells when i get the deletion part working correctly. The problem is with this code that dosnt matter if i insert or delete a cell or a column it treats it the same. Can anyone tell me whats wrong with my code?? How can i get it to only work deletion??? Then when that works how do I get it to track the insertion of a new row or collumn as well:


Code:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Dim What As String

If Target.Columns.Count = Columns.Count Then
    What = "Row " & Target.Row & " Deleted along with " & Target.Rows.Count - 1 & " additonal rows"
    Call DocumentChange(What)
End If

If Target.Rows.Count = Rows.Count Then
    What = "Column " & Target.Column & " Deleted along with " & Target.Columns.Count - 1 & " additonal columns"
    Call DocumentChange(What)
End If

End Sub


module:
Sub DocumentChange(What As String)
Dim r As Long
r = Sheet2.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row

Sheet2.Cells(r, 1) = What
Sheet2.Cells(r, 2) = Now
Sheet2.Cells(r, 3) = Environ("username")

End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

Forum statistics

Threads
1,214,827
Messages
6,121,809
Members
449,048
Latest member
greyangel23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top