Code that updates date automatically in adjacent cell, Now how to apply it to multiple Cells.

scout2489

New Member
Joined
Aug 1, 2014
Messages
4
Good Afternoon,

I looked around and pieced together this code that when a formula result changes in C3 it will put the current date in D3 to record the change. Now I am trying to figure out how to do this for C4 to D4, D5 to D5 and so on until C27 and D27. Could someone please help me with this?

Code:
Option Explicit
Public C3ValueOld As Variant


Private Sub Worksheet_Calculate()
    If Range("C3").Value <> C3ValueOld Then
        Range("D3").Value = Now()
        C3ValueOld = Range("C3").Value
    End If
End Sub


Thank you for any help or suggestions.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Code:
Option Explicit
Public C3ValueOld As Variant


Private Sub Worksheet_Calculate()


    For x = 3 To 27
    If Range("C" & x).Value <> C3ValueOld Then
        Range("D" & x).Value = Now()
        C3ValueOld = Range("C" & x).Value
    End If
     Next x
End Sub

I bet there's a non-looping way to do it, but for such a small data set it shouldn't impact run time. My only concern is the logic of matching it all to C3ValueOld and how that gets passed to the function.
 
Last edited:
Upvote 0
Thank you for the quick reply. I am getting a Compile Error: Variable not defined. Any ideas why?Thanks
 
Upvote 0
You shouldn't have to define x, but sometimes people come back saying you have to. So you could try to add:

Code:
Dim x as Long
 
Upvote 0
Alright I fixed that.Ok so now I need to change the variable X to be just the cell that has changed. Right now it will fill the whole range with today's date. I understand why it is doing this but I cannot think of the right way to change it to reflect. For X = 3 to 27 that has changed.
 
Last edited:
Upvote 0
Good Morning,To make this more clear I am trying to find a way to get adjacent cells to change when the formula calculates the new result from a new sheet. So C3 calculates and D3 updates with the current date and time. The formula I currently have which is above fills all cells in D3 to D27 when any update is made to C3 to C27. Thank you for your help!
 
Upvote 0

Forum statistics

Threads
1,221,418
Messages
6,159,791
Members
451,589
Latest member
Harold14

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