ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Update date when changing a cell (https://www.excelbanter.com/excel-programming/367193-update-date-when-changing-cell.html)

leonidas[_48_]

Update date when changing a cell
 

Hi,

I have a worksheet in excel with a lot of data on it. The data exists
of text, numbers and formulas.
I also have a date which should be updated to todays date when any of
the cell on the worksheet is changed.
Is it possible to do this and how should the code look like?
Thanks in advance for helping me!


--
leonidas
------------------------------------------------------------------------
leonidas's Profile: http://www.excelforum.com/member.php...o&userid=35375
View this thread: http://www.excelforum.com/showthread...hreadid=561410


Ardus Petus

Update date when changing a cell
 
Hi Leo,

Paste the following code in your worksheet's code (right-click on tab,
select View code)

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Range("A1").Value = Date
Application.EnableEvents = True
End Sub


HTH
--
AP

"leonidas" a écrit
dans le message de news:
...

Hi,

I have a worksheet in excel with a lot of data on it. The data exists
of text, numbers and formulas.
I also have a date which should be updated to todays date when any of
the cell on the worksheet is changed.
Is it possible to do this and how should the code look like?
Thanks in advance for helping me!


--
leonidas
------------------------------------------------------------------------
leonidas's Profile:
http://www.excelforum.com/member.php...o&userid=35375
View this thread: http://www.excelforum.com/showthread...hreadid=561410




Duncan[_5_]

Update date when changing a cell
 
Put this behind the worksheet code of the sheet you want it on.
(and change "A1" to the cell you want the date in)

Private Sub Worksheet_Change(ByVal Target As Range)
If Target = Range("A1") Then Exit Sub
Range("A1").Value = Now()
Range("A1").Copy
Range("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
End Sub


Duncan


leonidas wrote:

Hi,

I have a worksheet in excel with a lot of data on it. The data exists
of text, numbers and formulas.
I also have a date which should be updated to todays date when any of
the cell on the worksheet is changed.
Is it possible to do this and how should the code look like?
Thanks in advance for helping me!


--
leonidas
------------------------------------------------------------------------
leonidas's Profile: http://www.excelforum.com/member.php...o&userid=35375
View this thread: http://www.excelforum.com/showthread...hreadid=561410



Duncan[_5_]

Update date when changing a cell
 
Leo,

Forget my first post, this is a little better on the eyes. I typed too
fast last time and didnt set the target back to the cell you typed into
originally (which would be annoying when trying to input) and also
forgot to remove the cutcopymode.

Paste this in instead

Private Sub Worksheet_Change(ByVal Target As Range)
Dim OLDT As Range
If Target = Range("A1") Then Exit Sub
Set OLDT = Target
Range("A1").Value = Now()
Range("A1").Copy
Range("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
OLDT.Select
End Sub


btw: Ardus: wouldnt your sub loop indefinately?

Duncan


Ardus Petus wrote:

Hi Leo,

Paste the following code in your worksheet's code (right-click on tab,
select View code)

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Range("A1").Value = Date
Application.EnableEvents = True
End Sub


HTH
--
AP

"leonidas" a écrit
dans le message de news:
...

Hi,

I have a worksheet in excel with a lot of data on it. The data exists
of text, numbers and formulas.
I also have a date which should be updated to todays date when any of
the cell on the worksheet is changed.
Is it possible to do this and how should the code look like?
Thanks in advance for helping me!


--
leonidas
------------------------------------------------------------------------
leonidas's Profile:
http://www.excelforum.com/member.php...o&userid=35375
View this thread: http://www.excelforum.com/showthread...hreadid=561410



Duncan[_5_]

Update date when changing a cell
 
Ardus:

Sorry, your post is much easier than mine, I got carried away and made
it complicated.

It obviously doesnt go into an indefinate loop because you are not
selecting, I selected as from experiance when i put now() in it updated
so I had to paste as value, but in this case is not needed.

maybe mine is a little too complicated.......

Duncan


Ardus Petus wrote:

Hi Leo,

Paste the following code in your worksheet's code (right-click on tab,
select View code)

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Range("A1").Value = Date
Application.EnableEvents = True
End Sub


HTH
--
AP

"leonidas" a écrit
dans le message de news:
...

Hi,

I have a worksheet in excel with a lot of data on it. The data exists
of text, numbers and formulas.
I also have a date which should be updated to todays date when any of
the cell on the worksheet is changed.
Is it possible to do this and how should the code look like?
Thanks in advance for helping me!


--
leonidas
------------------------------------------------------------------------
leonidas's Profile:
http://www.excelforum.com/member.php...o&userid=35375
View this thread: http://www.excelforum.com/showthread...hreadid=561410




All times are GMT +1. The time now is 12:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com