Entering static Date/Time

  • Thread starter Thread starter GAMOSTEVE
  • Start date Start date
G

GAMOSTEVE

I'm trying to enter a date and a time in a worksheet if there is dat
entered into a particular cell. Example - Cell A contains data or nul
- if data, enter current date in Cell B and current time in cell C.

Problem I keep running into, the date/time updates to current with dat
entry into the next row.

Anyone have any ideas
 
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Columns.Count > 1 Then Exit Sub
If Target.Column <> 1 Then
Exit Sub
For Each cell In Target
If Not IsEmpty(cell) Then
Cells(Target.Row, "B").Value = Date
Cells(Target.Row, "C").Value = Time
Columns("B:C").AutoFit
End If
Next

End Sub

right click on the sheet tab and select view code. Paste in code like the
above.
 
Had some formatting problems:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim cell as Range
If Target.Columns.Count > 1 Then _
Exit Sub
If Target.Column <> 1 Then _
Exit Sub
For Each cell In Target
If Not IsEmpty(cell) Then
Cells(Target.Row, "B").Value = Date
Cells(Target.Row, "C").Value = Time
Columns("B:C").AutoFit
End If
Next

End Sub

--
Regards,
Tom Ogilvy

Tom Ogilvy said:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Columns.Count > 1 Then Exit Sub
If Target.Column <> 1 Then
Exit Sub
For Each cell In Target
If Not IsEmpty(cell) Then
Cells(Target.Row, "B").Value = Date
Cells(Target.Row, "C").Value = Time
Columns("B:C").AutoFit
End If
Next

End Sub

right click on the sheet tab and select view code. Paste in code like the
above.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top