if then statement = time

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do you write an "if' statement that will result in the pc system time.

Ex. IF cell A1>0, populate A2 with the system time that cell A1 was
populated.
 
You could write an IF statement using =NOW function but that will change
whenever calculation takes place.

You can use CTRL + SHIFT + ; to enter a static time.

Or event code to enter a static time.

The code below will enter a static time in column B when column A is populated
in the range of A1:A10

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range("A1:A10")) Is Nothing Then
With Target
If .Value <> "" Then
.Offset(0, 1).Value = Format(Now, "hh:mm:ss")
End If
End With
End If
ws_exit:
Application.EnableEvents = True
End Sub

This is event code. Right-click on the sheet tab and "View Code".

Copy/paste the code into that sheet module.


Gord Dibben MS Excel MVP
 

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