Automatic output of Date, Time & User (via VBA) on transactions is being erroneously updated when rows are deleted

Collie

New Member
Joined
Jan 26, 2021
Messages
10
Office Version
  1. 2016
Platform
  1. Windows
Hopefully my title hasn't been too confusing.

I have inserted VBA code into a worksheet to record when transactions were entered and by whom. One of the processes that run over month end determines where the transactions are to end up, and moves certain transactions by copying them to the new output and deleting the original. I have found that the deletion results in the next transaction to be erroneously stamped with the current date time and user.

Is there a solution? or a way to prevent the code from running when rows are being deleted?
this is the code I have in the worksheet:-


Private Sub Worksheet_Change(ByVal Target As Range)
Dim myTableRange As Range
Dim myDateRange As Range
Dim myTimeRange As Range
Dim myUser As Range

'code to automatically stamp trans with date, time & user
Set myTableRange = Range("B2:I10000")

If Intersect(Target, myTableRange) Is Nothing Then Exit Sub

Set myDateRange = Range("BL" & Target.Row)
Set myTimeRange = Range("BM" & Target.Row)
Set myUser = Range("BN" & Target.Row)

myDateRange.Value = DateValue(Now)
myTimeRange.Value = TimeValue(Now)
myUser.Value = Application.UserName
End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi again

I've still been searching the web looking for anything I can use as a solution..... Is it possible to test for a value (event) that has triggered the worksheet change? For example, if I could determine between changes, additions and deletions, and then not update the row on deletion, I would be alright.

Thanks in advance
 
Upvote 0
If entire rows are being deleted you could check the no of columns in Target.
VBA Code:
If Target.Columns.Count = Columns.Count Then
    ' row deleted
    Exit Sub
End If
 
Upvote 0
Solution
Hi Norie, I appreciate your reply, but would that identify differently for additions and changes compared to deletions?
 
Upvote 0
It would be for additions/deletions of entire rows.

Whenever you add/delete entire row(s) you are changing all the columns in the row(s).
 
Upvote 0
Thankyou Norie.:) tested through and through, and although I still don't fully understand the logic, I cant fault it and it is performing perfectly over the two thousand plus transactions in my worksheet.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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