VBA code to add current date when the sheet receive new update

Status
Not open for further replies.

Ramadan

Banned User
Joined
Jan 20, 2024
Messages
93
Office Version
  1. 2021
Platform
  1. Windows
I have a worksheet that only receive updates from other sheet with filter formula, no manual entry at all occurs in this sheet and I need a code to add the current date Now() in cell "C3" as soon as the sheet receive any update from the source sheet ..

I have a code but it insert the date based on sheet edit not update
any suggestions please..

VBA Code:
[Private Sub Worksheet_Change(ByVal Target As Range)
' Code to put the date of the latest update following a change in the corresponding cell in column F
    Dim WorkRng As Range, roww As Long
    Dim rng As Range
    Set WorkRng = Intersect(Range("P:O"), Target)
    If Not WorkRng Is Nothing Then
        Application.EnableEvents = False
            For Each rng In WorkRng
                roww = rng.Row
                If Not rng.Value = "" Then
                    Range("C3").Value = Now
                    Range("C3").NumberFormat = "yy/mm/dd"
                Else
                    Range("C3").ClearContents
                End If
            Next
        Application.EnableEvents = True
        
    End If]
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Hi, use the
VBA Code:
Option Explicit

Private Sub Worksheet_Calculate()
    ' your code here
End Sub
or
Code:
Option Explicit

Private Sub Worksheet_Activate()
    ' your code here
End Sub
or
Code:
Option Explicit

Private Sub Worksheet_Deactivate()
    ' your code here
End Sub
 
Upvote 0
Hi, use the
VBA Code:
Option Explicit

Private Sub Worksheet_Calculate()
    ' your code here
End Sub
or
Code:
Option Explicit

Private Sub Worksheet_Activate()
    ' your code here
End Sub
or
Code:
Option Explicit

Private Sub Worksheet_Deactivate()
    ' your code here
End Sub
I got this error
Untitled.jpg
 
Upvote 0
How does the sheet update with data? If with another macro, then it is possible to immediately supplement it with an additional line of code for entering the date.
 
Upvote 0
How does the sheet update with data? If with another macro, then it is possible to immediately supplement it with an additional line of code for entering the date.
the sheet receive update from another sheet in the same workbook through FILTER formula no macros
 
Upvote 0
Ok, try next code:
VBA Code:
Option Explicit

Private Sub Worksheet_Calculate()
    Dim rng         As Range
    Application.EnableEvents = False

    Dim LastRow     As Long
    LastRow = Me.Cells(Me.Rows.Count, "P").End(xlUp).Row
    If LastRow < 1 Then Exit Sub

    Dim WorkRng     As Range
    Set WorkRng = Me.Range("O1:P" & LastRow)

    For Each rng In WorkRng

        If Not IsEmpty(rng.Value) Then
            Me.Range("C3").Value = Now
            Me.Range("C3").NumberFormat = "yy/mm/dd"
            Exit For
        Else
            Me.Range("C3").ClearContents
        End If

    Next rng

    Set WorkRng = Nothing
    Application.EnableEvents = True
End Sub
 
Upvote 0
Ok, try next code:
VBA Code:
Option Explicit

Private Sub Worksheet_Calculate()
    Dim rng         As Range
    Application.EnableEvents = False

    Dim LastRow     As Long
    LastRow = Me.Cells(Me.Rows.Count, "P").End(xlUp).Row
    If LastRow < 1 Then Exit Sub

    Dim WorkRng     As Range
    Set WorkRng = Me.Range("O1:P" & LastRow)

    For Each rng In WorkRng

        If Not IsEmpty(rng.Value) Then
            Me.Range("C3").Value = Now
            Me.Range("C3").NumberFormat = "yy/mm/dd"
            Exit For
        Else
            Me.Range("C3").ClearContents
        End If

    Next rng

    Set WorkRng = Nothing
    Application.EnableEvents = True
End Sub
I tried it but nothing happened - if it would be easier you can adjust the original code I have in my question to be linked to the source sheet in the same workbook I think it will proceed the same result if any edit done in it - the source sheet name is "Database"
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,225,504
Messages
6,185,363
Members
453,288
Latest member
rlmorales2000

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