Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Worksheet Change Event

Hello. Within the range of Sheet1 D4:D2500, how can I take a date that is
entered into a cell and convert the DAY to a 1, keeping all else the same?

So for example, if the user enters 12/15/2005 in cell D25, then I would like
the change event to trigger and convert that cell into 12/1/2005.

Thank you!


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default Worksheet Change Event

try

Sub changedayto1()
For Each c In Selection
c.Value = DateSerial(Year(c), Month(c), 1)
Next

--
Don Guillett
SalesAid Software

"Steph" wrote in message
...
Hello. Within the range of Sheet1 D4:D2500, how can I take a date that is
entered into a cell and convert the DAY to a 1, keeping all else the same?

So for example, if the user enters 12/15/2005 in cell D25, then I would

like
the change event to trigger and convert that cell into 12/1/2005.

Thank you!




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Worksheet Change Event

Hi Don,

I tried to apply what you gave me in a worksheet change event:
'Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 4 And Target.Row 11 And Target.Row < 2500 Then
Cells(Target.Row, 4).Value = DateSerial(Year(Cells(Target.Row, 4)),
Month(Cells(Target.Row, 4)), 1)
End If
End Sub

It works, but it's throwing things into an eternal loop. I heard of this
happening to change events, but don't know how to fix it. Thanks.

"Don Guillett" wrote in message
...
try

Sub changedayto1()
For Each c In Selection
c.Value = DateSerial(Year(c), Month(c), 1)
Next

--
Don Guillett
SalesAid Software

"Steph" wrote in message
...
Hello. Within the range of Sheet1 D4:D2500, how can I take a date that

is
entered into a cell and convert the DAY to a 1, keeping all else the

same?

So for example, if the user enters 12/15/2005 in cell D25, then I would

like
the change event to trigger and convert that cell into 12/1/2005.

Thank you!






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Worksheet Change Event

One way:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If .Count 1 Then Exit Sub
If Not Intersect(Range("D4:D2500"), .Cells) Is Nothing Then
Application.EnableEvents = False
If IsDate(.Value) Then _
.Value = DateSerial(Year(.Value), Month(.Value), 1)
Application.EnableEvents = True
End If
End With
End Sub


In article ,
"Steph" wrote:

Hello. Within the range of Sheet1 D4:D2500, how can I take a date that is
entered into a cell and convert the DAY to a 1, keeping all else the same?

So for example, if the user enters 12/15/2005 in cell D25, then I would like
the change event to trigger and convert that cell into 12/1/2005.

Thank you!

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Worksheet Change Event

See my other post.

In article ,
"Steph" wrote:

It works, but it's throwing things into an eternal loop. I heard of this
happening to change events, but don't know how to fix it. Thanks.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Worksheet Change Event

Thanks so much!

"JE McGimpsey" wrote in message
...
One way:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If .Count 1 Then Exit Sub
If Not Intersect(Range("D4:D2500"), .Cells) Is Nothing Then
Application.EnableEvents = False
If IsDate(.Value) Then _
.Value = DateSerial(Year(.Value), Month(.Value), 1)
Application.EnableEvents = True
End If
End With
End Sub


In article ,
"Steph" wrote:

Hello. Within the range of Sheet1 D4:D2500, how can I take a date that

is
entered into a cell and convert the DAY to a 1, keeping all else the

same?

So for example, if the user enters 12/15/2005 in cell D25, then I would

like
the change event to trigger and convert that cell into 12/1/2005.

Thank you!



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
Worksheet Change Event DCSwearingen Excel Discussion (Misc queries) 1 October 10th 05 10:25 PM
Worksheet Row Change event crazybass2 Excel Discussion (Misc queries) 4 December 8th 04 05:29 PM
Worksheet Change event Libby Excel Programming 2 October 26th 04 12:02 AM
Change Cell from Validated List Not Firing Worksheet Change Event [email protected] Excel Programming 3 October 4th 04 03:00 AM


All times are GMT +1. The time now is 06:56 PM.

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"