Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default auto running macro

I have to have the date added automatically in column H if the info is added
in column F of the same row. The code I wrote works but I have to return to
column F after the info is added in F and only after that reverse-move does
the required info appear in H
Where is my mistake and how to fix this problem?
Thanks!
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim myCell As Range
If Intersect(Target, Range("F:F")) Is Nothing Then Exit Sub
ApplicationEnableEvents = False
Range("H:H").NumberFormat = "mm/dd/yyyy"
For Each myCell In Intersect(Target, Range("F:F"))
rw = myCell.Row
Cells(rw, "H").FormulaR1C1 = "=IF(RC[-2]<"""", Now(), """")"
Cells(rw, "H").Value = Cells(rw, "H").Value
Cells(rw, "M").Value = Environ("UserName")
Next myCell
Application.EnableEvents = True
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default auto running macro

Hi

You are using 'Worksheet_SelectionChange' event but you should use
'Worksheet_Change' event.


So just remove 'Selection' from the line below....

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Regards,
Per

On 12 Nov., 23:16, Maryna wrote:
I have to have the date added *automatically in column H if the info is added
in column F of the same row. The code I wrote works but I have to return to
column F after the info is added in F and only after that reverse-move does
the required info appear in H
Where is my mistake and how to fix this problem?
Thanks!
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim myCell As Range
If Intersect(Target, Range("F:F")) Is Nothing Then Exit Sub
ApplicationEnableEvents = False
Range("H:H").NumberFormat = "mm/dd/yyyy"
For Each myCell In Intersect(Target, Range("F:F"))
rw = myCell.Row
Cells(rw, "H").FormulaR1C1 = "=IF(RC[-2]<"""", Now(), """")"
Cells(rw, "H").Value = Cells(rw, "H").Value
Cells(rw, "M").Value = Environ("UserName")
Next myCell
Application.EnableEvents = True
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default auto running macro

Wrong event type.

Also some unneeded stuff in there with the formulas and change to values.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim myCell As Range
If Intersect(Target, Range("F:F")) Is Nothing Then Exit Sub
On Error GoTo endit
Application.EnableEvents = False
With Target
If .Value < "" Then
.Offset(0, 2).Value = Format(Now, "mm/dd/yy")
.Offset(0, 7).Value = Environ("Username")
End If
End With
endit:
Application.EnableEvents = True
End Sub


Gord Dibben MS Excel MVP

On Thu, 12 Nov 2009 14:16:01 -0800, Maryna
wrote:

I have to have the date added automatically in column H if the info is added
in column F of the same row. The code I wrote works but I have to return to
column F after the info is added in F and only after that reverse-move does
the required info appear in H
Where is my mistake and how to fix this problem?
Thanks!
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim myCell As Range
If Intersect(Target, Range("F:F")) Is Nothing Then Exit Sub
ApplicationEnableEvents = False
Range("H:H").NumberFormat = "mm/dd/yyyy"
For Each myCell In Intersect(Target, Range("F:F"))
rw = myCell.Row
Cells(rw, "H").FormulaR1C1 = "=IF(RC[-2]<"""", Now(), """")"
Cells(rw, "H").Value = Cells(rw, "H").Value
Cells(rw, "M").Value = Environ("UserName")
Next myCell
Application.EnableEvents = True
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
Auto running a macro on closing Jimmy D Excel Discussion (Misc queries) 6 November 22nd 07 01:58 AM
Running a macro from an auto-refresh Chris Youlden Excel Worksheet Functions 2 October 7th 07 04:22 PM
Auto Running a macro when a field has changed RaY Excel Programming 3 September 1st 06 03:10 AM
Auto Running a macro on open Jamie Excel Programming 2 May 24th 05 05:52 PM
Stoping an Auto Open macro from running RzB Excel Programming 7 December 5th 03 02:36 AM


All times are GMT +1. The time now is 01:45 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"