ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   I need a function that will trap & manage a change in cell value (https://www.excelbanter.com/excel-programming/386150-re-i-need-function-will-trap-manage-change-cell-value.html)

Tom Ogilvy

I need a function that will trap & manage a change in cell value
 
Right click on the sheet tab and select View Code.
in the resulting module, paste in code like this:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
If Target.Count 1 Then Exit Sub
On Error GoTo ErrHandler
' use your list of cells to react to
Set rng = Range("B1,C11,D12,M21,A5:A30,C1:C5")
If Not Intersect(Target, rng) Is Nothing Then
Application.EnableEvents = False
Target.Offset(0, 1).Value = Now
Target.Offset(0, 1).NumberFormat = "mm/dd/yyyy hh:mm"
Target.Offset(0, 1).EntireColumn.AutoFit
End If
ErrHandler:
Application.EnableEvents = True

End Sub

this uses the worksheet Change event. If you are not familiar with events,
see Chip Pearson's site
http://www.cpearson.com/excel/events.htm

--
Regards,
Tom Ogilvy

"Terry" wrote:

Scenario
A value exists in a cell
The value in the cell is changed by data entry
A date would be populated in an adjacent cell reflecting the date of change
- for that cell only
My worksheet has numerous places that this function would need to work



All times are GMT +1. The time now is 03:48 AM.

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