Jyggalag

Active Member
Joined
Mar 8, 2021
Messages
422
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi all,

I have this formula:

1652449248970.png


Essentially, when I fill in ANY data or make ANY changes to cell D2, i want the VBA to automatically update the current date/time in cell B1, so I can see the last time I made any update to cell D2.

I can do xOffsetColumn = -2

But this will show the date in cell B2, not B1.

Also, referencing the code to "B1" does not work, as you can see above.

Does anybody know how to fix my code so I can refer to cell B1?

Thank you! :)
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
xOffsetColumn=-2 ---you don't need to change this line.
Rng.offset(-1,xOffsetColumn) ---Three lines should be like this.
 
Upvote 0
Throw away that code and use this.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

   If Not Intersect([D2], Target) Is Nothing Then
      Application.EnableEvents = False
      [B1] = Date
      Application.EnableEvents = True
   End If

End Sub
 
Upvote 0
Solution
Also note that is you declare xOffsetColumn as an Integer (like you did in your code), you cannot set it equal to "B1", as "B1" is text, NOT an integer!
 
Upvote 0
tri
xOffsetColumn=-2 ---you don't need to change this line.
Rng.offset(-1,xOffsetColumn) ---Three lines should be like this.
tried this :( didnt work, it gives an error for "Rng.offset(-1, xOffsetColumn)
 
Upvote 0
Throw away that code and use this.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

   If Not Intersect([D2], Target) Is Nothing Then
      Application.EnableEvents = False
      [B1] = Date
      Application.EnableEvents = True
   End If

End Sub
This is great and it works!

But it only shows the date, not the time, any way to fix this?
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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