Adding date of updated cells

JamesL

Board Regular
Joined
Apr 21, 2004
Messages
113
Hi,

I have the following code for when a cell is changed the date and time and another piece of info are applied to a specfic cell.

This in principal works fine (utilising Target), however the code is more complicated due to each input row is made up of three rows (i.e merged), apart from the last three rows and columns which make up a 3x3 matrix. Hence in the code why it looks for the position of "SRT" which represents the top of the three rows. This is where the row there the date should appear, even if the 3x3 matrix is changed.

The code below seems to run for ages and when you step through it get through part of the code and then starts again?

Is there a better way of doing this and why does this code not work!??

Sorry can't attach a picture due to company restrictions.


Thanks in advance
James

'''''''''''''''''''''''''''''''

Private Sub Worksheet_Change(ByVal Target As Range)
'Applies last updated to each line

If Target.Row >= 15 And _
Target.Row <= Sheet4.Cells(6, 4) Then
If Sheet1.Cells(Target.Row, 52) = "Srt" Then
Sheet1.Cells(Target.Row, 53) = Now
Sheet1.Cells(Target.Row, 54) = Sheet4.Cells(7, 4)
ElseIf Sheet1.Cells(Target.Row - 1, 52) = "Srt" Then
Sheet1.Cells(Target.Row - 1, 53) = Now
Sheet1.Cells(Target.Row, 54) = Sheet4.Cells(7, 4)
ElseIf Sheet1.Cells(Target.Row - 2, 52) = "Srt" Then
Sheet1.Cells(Target.Row - 2, 53) = Now
Sheet1.Cells(Target.Row, 54) = Sheet4.Cells(7, 4)
End If
End If

End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Von Pookie

MrExcel MVP
Joined
Feb 17, 2002
Messages
13,686
The code below seems to run for ages and when you step through it get through part of the code and then starts again?
You have to set EnableEvents to false. When the code enters the date, it is triggering the macro again and it "restarts". Don't forget to set it back to "True" at the end of the macro, or none of your event macros (such as Worksheet_Change, here) will run).

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = False

If Target.Row >= 15 And Target.Row <= Sheet4.Cells(6, 4) Then
    If Sheet1.Cells(Target.Row, 52) = "Srt" Then
        Sheet1.Cells(Target.Row, 53) = Now
        Sheet1.Cells(Target.Row, 54) = Sheet4.Cells(7, 4)
    ElseIf Sheet1.Cells(Target.Row - 1, 52) = "Srt" Then
        Sheet1.Cells(Target.Row - 1, 53) = Now
        Sheet1.Cells(Target.Row, 54) = Sheet4.Cells(7, 4)
    ElseIf Sheet1.Cells(Target.Row - 2, 52) = "Srt" Then
        Sheet1.Cells(Target.Row - 2, 53) = Now
        Sheet1.Cells(Target.Row, 54) = Sheet4.Cells(7, 4)
    End If
End If

Application.EnableEvents = True

End Sub
 

Forum statistics

Threads
1,141,137
Messages
5,704,490
Members
421,353
Latest member
jekoxien15

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
Top