Macro to populate date when there is a change in the cell/Row

petes

Board Regular
Joined
Sep 12, 2009
Messages
168
I need to alter this code so that, only when there is change in RowID 5, the date should be populated. Currently, the date is populating whenever the cursor comes to that row (irrespective of changes).

Also, I need this for 1000 Rows (from D5 to D1000)

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If (Target.Row = 5) Then
range("D5").formula="=today()"


End If
End Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Perhaps like this

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row >= 5 And Target.Row <= 1000 Then
    Application.EnableEvents = False
    Cells(Target.Row, 4).Value = Date
    Application.EnableEvents = True
End If
End Sub
 
Upvote 0
This is exactly what i wanted, but now i need some further improvements--

The date should be populated only if the specific cells gets changed.
Those specific cells are A5, C5, E5, F5, J5 (Similarly for rest 1000 cells)
 
Upvote 0
Try

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row >= 5 And Target.Row <= 1000 Then
    If Target.Column = 1 Or Target.Column = 3 Or Target.Column = 5 Or Target.Column = 6 Or Target.Column = 10 Then
        Application.EnableEvents = False
        Cells(Target.Row, 4).Value = Date
        Application.EnableEvents = True
    End If
End If
End Sub
 
Upvote 0
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Row >= 5 And Target.Row <= 1000 Then
        Select Case Target.Column
            Case 1, 3, 5, 6, 10
                Application.EnableEvents = False
                Cells(Target.Row, "D").Value = Date
        End Select
    End If
safeExit:
    Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,507
Messages
6,179,181
Members
452,893
Latest member
denay

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