Trying to get date to enter a cell

B

Bob Vance

Trying to get the date entered into column B when something is entered into
the ajoining cell in A row, was advised this would work, but it dosent seem
too, any help please
--
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Count > 1 Then Exit Sub
If Intersect(Target, Range("A:A")) Is Nothing Then Exit
Sub

On Error GoTo Errorline:

Application.EnableEvents = False
With Target
If Len(.Value) > 0 Then
.Offset(, 1) = Format(Now(), "mm/dd/yy")
End If
End With



Thanks in advance for your help....Bob Vance
 
V

Vasant Nanavati

The basic code would be:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 2 And Target <> "" Then Target.Offset(, -1) = Date
End Sub

It will need some error-checking for simultaneous changes to multiple cells,
etc.
 
B

Bob Phillips

Bob,

I just entered this code and it worked fine for me. I can only guess that
you are not loading the code into the correct module, it should go into your
worksheet code module. To get at this, on the appropriate worksheet,
right-click the sheet tab name, and from the menu select 'View Code'. This
takes you into the worksheet code module, and selects the code pane, where
you should enter that code.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
B

Bob Vance

Funny That because Vasant Script worked perfectly, Thanks for all your help,
works great :)
 
V

Vasant Nanavati

Actually, I'm surprised my code worked because I think I got columns A and B
confused. But hey, whatever works ... <g>
 

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

Top