PC Review


Reply
Thread Tools Rate Thread

Date Macro if B is populated then date in A

 
 
=?Utf-8?B?UmVmTGliMTk3OA==?=
Guest
Posts: n/a
 
      23rd Aug 2007
Hi - I'm truly sorry if this question has already been answered. I've lost so
much time trying to solve something that seemed so simple, so I'm posting in
the hope that someone can help me. I am trying to make a condition macro so
that when a cell in the B column is not blank, then that day's date will
automatically be in the A cell right next to it. I also need it to remain
that date. Basically, I have a worksheet to track purchases so I need to get
the date to go into the A column as soon as the B column get a title. So for
example:

A B
Today Book Title

Here's the macro that I have so far:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If .Count > 1 Then Exit Sub
If Not Intersect(Range("b:b"), .Cells) Is Nothing Then
Application.EnableEvents = False
If IsEmpty(.Value) Then
..Offset(0, 1).ClearContents
Else
With .Offset(.Column, 0, 1)
..NumberFormat = "mm/dd/yyyy"
..Value = Now
End With
End If
Application.EnableEvents = True
End If
End With
End Sub

I figure it's a simple tweak, but I've been unsuccessful in getting the date
into the A cell. Can anyone help?
 
Reply With Quote
 
 
 
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      23rd Aug 2007
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If .Count > 1 Then Exit Sub
If .Column <> 2 Then exit sub
Application.EnableEvents = False
If IsEmpty(.Value) Then
.Offset(0, -1).ClearContents
Else
With .Offset(0,-1)
.NumberFormat = "mm/dd/yyyy"
.Value = Now
End With
End If
end With
Application.EnableEvents = True

End Sub

--
Regards,
Tom Ogilvy

"RefLib1978" wrote:

> Hi - I'm truly sorry if this question has already been answered. I've lost so
> much time trying to solve something that seemed so simple, so I'm posting in
> the hope that someone can help me. I am trying to make a condition macro so
> that when a cell in the B column is not blank, then that day's date will
> automatically be in the A cell right next to it. I also need it to remain
> that date. Basically, I have a worksheet to track purchases so I need to get
> the date to go into the A column as soon as the B column get a title. So for
> example:
>
> A B
> Today Book Title
>
> Here's the macro that I have so far:
>
> Private Sub Worksheet_Change(ByVal Target As Excel.Range)
> With Target
> If .Count > 1 Then Exit Sub
> If Not Intersect(Range("b:b"), .Cells) Is Nothing Then
> Application.EnableEvents = False
> If IsEmpty(.Value) Then
> .Offset(0, 1).ClearContents
> Else
> With .Offset(.Column, 0, 1)
> .NumberFormat = "mm/dd/yyyy"
> .Value = Now
> End With
> End If
> Application.EnableEvents = True
> End If
> End With
> End Sub
>
> I figure it's a simple tweak, but I've been unsuccessful in getting the date
> into the A cell. Can anyone help?

 
Reply With Quote
 
=?Utf-8?B?R2FyeScncyBTdHVkZW50?=
Guest
Posts: n/a
 
      23rd Aug 2007
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If .Count > 1 Then Exit Sub
If Not Intersect(Range("b:b"), .Cells) Is Nothing Then
Application.EnableEvents = False
If IsEmpty(.Value) Then
.Offset(0, -1).ClearContents
Else

.Offset(0, -1).NumberFormat = "mm/dd/yyyy"
.Offset(0, -1).Value = Now

End If
Application.EnableEvents = True
End If
End With
End Sub


--
Gary''s Student - gsnu200738


"RefLib1978" wrote:

> Hi - I'm truly sorry if this question has already been answered. I've lost so
> much time trying to solve something that seemed so simple, so I'm posting in
> the hope that someone can help me. I am trying to make a condition macro so
> that when a cell in the B column is not blank, then that day's date will
> automatically be in the A cell right next to it. I also need it to remain
> that date. Basically, I have a worksheet to track purchases so I need to get
> the date to go into the A column as soon as the B column get a title. So for
> example:
>
> A B
> Today Book Title
>
> Here's the macro that I have so far:
>
> Private Sub Worksheet_Change(ByVal Target As Excel.Range)
> With Target
> If .Count > 1 Then Exit Sub
> If Not Intersect(Range("b:b"), .Cells) Is Nothing Then
> Application.EnableEvents = False
> If IsEmpty(.Value) Then
> .Offset(0, 1).ClearContents
> Else
> With .Offset(.Column, 0, 1)
> .NumberFormat = "mm/dd/yyyy"
> .Value = Now
> End With
> End If
> Application.EnableEvents = True
> End If
> End With
> End Sub
>
> I figure it's a simple tweak, but I've been unsuccessful in getting the date
> into the A cell. Can anyone help?

 
Reply With Quote
 
=?Utf-8?B?UmVmTGliMTk3OA==?=
Guest
Posts: n/a
 
      23rd Aug 2007
Thank you so much. It worked! I really appreciate it.

"Gary''s Student" wrote:

> Private Sub Worksheet_Change(ByVal Target As Excel.Range)
> With Target
> If .Count > 1 Then Exit Sub
> If Not Intersect(Range("b:b"), .Cells) Is Nothing Then
> Application.EnableEvents = False
> If IsEmpty(.Value) Then
> .Offset(0, -1).ClearContents
> Else
>
> .Offset(0, -1).NumberFormat = "mm/dd/yyyy"
> .Offset(0, -1).Value = Now
>
> End If
> Application.EnableEvents = True
> End If
> End With
> End Sub
>
>
> --
> Gary''s Student - gsnu200738
>
>
> "RefLib1978" wrote:
>
> > Hi - I'm truly sorry if this question has already been answered. I've lost so
> > much time trying to solve something that seemed so simple, so I'm posting in
> > the hope that someone can help me. I am trying to make a condition macro so
> > that when a cell in the B column is not blank, then that day's date will
> > automatically be in the A cell right next to it. I also need it to remain
> > that date. Basically, I have a worksheet to track purchases so I need to get
> > the date to go into the A column as soon as the B column get a title. So for
> > example:
> >
> > A B
> > Today Book Title
> >
> > Here's the macro that I have so far:
> >
> > Private Sub Worksheet_Change(ByVal Target As Excel.Range)
> > With Target
> > If .Count > 1 Then Exit Sub
> > If Not Intersect(Range("b:b"), .Cells) Is Nothing Then
> > Application.EnableEvents = False
> > If IsEmpty(.Value) Then
> > .Offset(0, 1).ClearContents
> > Else
> > With .Offset(.Column, 0, 1)
> > .NumberFormat = "mm/dd/yyyy"
> > .Value = Now
> > End With
> > End If
> > Application.EnableEvents = True
> > End If
> > End With
> > End Sub
> >
> > I figure it's a simple tweak, but I've been unsuccessful in getting the date
> > into the A cell. Can anyone help?

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Return first date populated T. Valko Microsoft Excel Worksheet Functions 0 28th Apr 2009 05:03 AM
Re: Return first date populated T. Valko Microsoft Excel Worksheet Functions 0 27th Apr 2009 07:33 PM
::: Date Comparison Problem or Date Formula or Date Macro ::: infojacques@gmail.com Microsoft Excel Discussion 3 13th Jul 2007 10:08 AM
i have two date fileds Opend date Due date, can i set default on due date so, its always = to open date on my data entry form1 Urgent Mike Saifie Microsoft Access Form Coding 1 9th Mar 2006 01:08 AM
Need 'date added' column populated David Microsoft Access Forms 1 8th Dec 2003 06:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:21 PM.