Vba experts: Need help with date and time stamp being static

bamaisgreat

Well-known Member
Joined
Jan 23, 2012
Messages
834
Office Version
  1. 365
Platform
  1. Windows
Thanks for looking the code below is what Im currently using. I need to modify this so it does not look in the entire row.
Example: instead of it looking in column 3 and 20 i need to look at column 3 and 20 down to row 25 starting with row 4.


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 3 Then
        Application.EnableEvents = False
        Cells(Target.Row, 20).Value = Date + Time
        Application.EnableEvents = True
        End If
        
End Sub
 
try:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("$C$4:$C$25")) Is Nothing Then
  Application.EnableEvents = False
  Cells(Target.Row, 20).Value = Date + Time
  Application.EnableEvents = True
End If
End Sub
 
Upvote 0
Thanks p45cal, I have run into another issue with it. I have this in a module
Sub savee()
ActiveSheet.Unprotect
Dim cell As Range
For Each cell In Range("A4:E22")
If Not cell.HasFormula Then
cell.Value = UCase(cell.Value)
End If
Next cell

For Each cell In Range("G4:K22")
If Not cell.HasFormula Then
cell.Value = UCase(cell.Value)
End If
Next cell



Range("h4").Select
ActiveSheet.Protect
ActiveWorkbook.Save
End Sub
and when it runs it changes all the dates and times in the selected dells to current and fills in the ones that were blank. Any suggestions ?
 
Upvote 0
Range("A4:E22") includes the cells C4:C25, perhaps try putting Application.enableevents = False before the line For Each cell In Range("A4:E22") and Application.enableevents = true after the line Next Cell:
Code:
Sub savee()
    ActiveSheet.Unprotect
Dim cell As Range
    [COLOR=#ff0000]Application.enableevents = False[/COLOR]
    For Each cell In Range("A4:E22")
        If Not cell.HasFormula Then
            cell.Value = UCase(cell.Value)
        End If
    Next cell
    [COLOR=#ff0000]Application.enableevents = True[/COLOR]

     For Each cell In Range("G4:K22")
        If Not cell.HasFormula Then
            cell.Value = UCase(cell.Value)
        End If
    Next cell
    
    Range("h4").Select
    ActiveSheet.Protect
    ActiveWorkbook.Save
End Sub
 
Upvote 0
P45cal thanks for all your help. I have one other issue. The code below is what Im using.
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("$C$4:$C$22")) Is Nothing Then
Application.EnableEvents = False
Cells(Target.Row, 20).Value = Date + Time
Application.EnableEvents = True
End If
End Sub
Is there away if someone enters data in say C4 and then they delete that data that the date and time that is in row 20 will go away also. Thanks
 
Upvote 0
Is there away if someone enters data in say C4 and then they delete that data that the date and time that is in row 20 will go away also.
Try changing:
Code:
Cells(Target.Row, 20).Value = Date + Time
to:
Code:
  If Len(Target.Value) > 0 Then Cells(Target.Row, 20).Value = Date + Time Else Cells(Target.Row, 20).Value = ""
 
Upvote 0
ok that worked great. The cells are protected, is there away to get around that.
 
Upvote 0
have:
Me.Protect userinterfaceonly:=True
in the change event before it tries to change anything.

However, rather than put this in the sheet's change event which will have it executed a zillion times, you could put it into the workbook open event but you need to tell it which sheet, so:
Sheets("TheNameOfTheSheetHere").Protect userinterfaceonly:=True

Wolf? Who he?
 
Upvote 0

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