Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Event to add a date if "X" is entered in a cell

How do I modify this code to put a date in only if a capital x exists in the
adjacent cell?



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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Event to add a date if "X" is entered in a cell

Hi,

Try this

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

Mike

"JOSEPH WEBER" wrote:

How do I modify this code to put a date in only if a capital x exists in the
adjacent cell?



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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Event to add a date if "X" is entered in a cell

I misunderstood your requirement, try this instead

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

Mike

"Mike H" wrote:

Hi,

Try this

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

Mike

"JOSEPH WEBER" wrote:

How do I modify this code to put a date in only if a capital x exists in the
adjacent cell?



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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default Event to add a date if "X" is entered in a cell

if you're not too worried about row number then

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
if Target.Column = 3 and Target="X" then
target.offset(,1).Resize(1,1)=Date
End Sub

....is nice and simple

you might want to include a .Count check like Mike did, if there's a
possibility of multiple cell entry

"JOSEPH WEBER" wrote in message
...
How do I modify this code to put a date in only if a capital x exists in
the
adjacent cell?



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


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
Conditional Formatting on "Any Text" entered in a cell Chris Mather Excel Discussion (Misc queries) 5 April 3rd 23 01:11 PM
creating a "date selector box" or "pull down box" in a cell GaryK Excel Worksheet Functions 2 September 30th 09 01:45 AM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
bunch of "yes" or "no" entered in row, output 1 if a single yes dan2201 Excel Worksheet Functions 9 September 7th 06 05:05 PM
Macro that runs entered value through "low" and "high" range Vika.F Excel Programming 5 August 14th 05 08:35 AM


All times are GMT +1. The time now is 05:37 PM.

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

About Us

"It's about Microsoft Excel"