Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Date Macro if B is populated then date in A

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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Date Macro if B is populated then date in A

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?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Date Macro if B is populated then date in A

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?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Date Macro if B is populated then date in A

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Return first date populated Pleasehelp via OfficeKB.com Excel Worksheet Functions 4 April 28th 09 05:03 AM
How do I merge date from two populated columns into one column? Morgan788 Setting up and Configuration of Excel 0 June 11th 08 03:16 PM
auto enter date when another cell populated? zim New Users to Excel 6 March 2nd 07 05:40 PM
Payment cell populated based on date formula TonyD Excel Discussion (Misc queries) 6 January 31st 07 09:55 AM
Entering date depending on another cell being populated wurz Excel Programming 3 June 21st 06 12:03 PM


All times are GMT +1. The time now is 03:43 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"