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
 

Some videos you may like

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

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
 

Watch MrExcel Video

Forum statistics

Threads
1,109,423
Messages
5,528,681
Members
409,829
Latest member
CFreeamaz

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top