Suspend Code When Row is Deleted

belmontry

New Member
Joined
Jun 28, 2011
Messages
2
I am running the following to automatically date stamp a range of data when anything in its respective row is modified:

Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("A2:AA7000")) Is Nothing Then Exit Sub
    
    Application.EnableEvents = False
    Range("A" & Target.Row) = Date
    Application.EnableEvents = True
    
End Sub

However, I often need to delete entire rows from the sheet. In doing so, the code effectively date stamps the sequential row that was previously deleted, although I have not intentionally input any data. Example: If I want to delete a full row of data in Sheet Row C, I delete the selected Row C, but the subsequent new Row C (previously Row D) is date stamped since its contents were modified to the new Row C locations.

I don’t know what to do to prevent the date stamp from running if, and only if, a row of data is deleted from the spreadsheet.

Thanks
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi,

Try:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
    If Intersect(Target, Range("A2:AA7000")) Is Nothing Then Exit Sub
    
    Application.EnableEvents = False
    Range("A" & Target.Row) = Date
    Application.EnableEvents = True
    
End Sub

Assuming that you will only ever enter data into one cell at a time.
 
Upvote 0
Welcome to the board..

Try this as the first line in the code..

If Target.Columns.Count = Columns.Count Then Exit Sub

Hope that helps
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,786
Members
452,942
Latest member
VijayNewtoExcel

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