Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
sby sby is offline
external usenet poster
 
Posts: 7
Default Private sub problem

Hi

I have the following code in a excel worksheet, but the last bit does not run.
It should move data from one column to the previous one which works fine.
The second part should show when the data was last updated.

They both work separately but when I add them together I get an "ambiguous
error". I have renamed the second sub to what it is below instead of
"worksheet_change" as the first one but now the second sub does not run.

Can anybody help and explain why.

Here is the code:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)

If Intersect(Target, Range("D:D")) Is Nothing Then Exit Sub

Application.EnableEvents = False
Cells(Target.Row, 3).Value = Cells(Target.Row, 5).Value
Cells(Target.Row, 5).Value = Cells(Target.Row, 4).Value
Application.EnableEvents = True

End Sub


Private Sub Worksheet_Date(ByVal Target As Excel.Range)

If Target.Column = 1 Then
Target.Offset(0, 1).Value = Now()
End If
End Sub


Thanks

SBY


  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,441
Default Private sub problem

You don't get to name events - Excel only has predetermined events. Just change your first event to
include the time stamp:


Private Sub Worksheet_Change(ByVal Target As Excel.Range)

If Intersect(Target, Range("D:D")) Is Nothing Then Exit Sub

Application.EnableEvents = False
Cells(Target.Row, 2).Value = Now()
Cells(Target.Row, 3).Value = Cells(Target.Row, 5).Value
Cells(Target.Row, 5).Value = Cells(Target.Row, 4).Value
Application.EnableEvents = True

End Sub


--
HTH,
Bernie
MS Excel MVP


"sby" wrote in message
...
Hi

I have the following code in a excel worksheet, but the last bit does not run.
It should move data from one column to the previous one which works fine.
The second part should show when the data was last updated.

They both work separately but when I add them together I get an "ambiguous
error". I have renamed the second sub to what it is below instead of
"worksheet_change" as the first one but now the second sub does not run.

Can anybody help and explain why.

Here is the code:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)

If Intersect(Target, Range("D:D")) Is Nothing Then Exit Sub

Application.EnableEvents = False
Cells(Target.Row, 3).Value = Cells(Target.Row, 5).Value
Cells(Target.Row, 5).Value = Cells(Target.Row, 4).Value
Application.EnableEvents = True

End Sub


Private Sub Worksheet_Date(ByVal Target As Excel.Range)

If Target.Column = 1 Then
Target.Offset(0, 1).Value = Now()
End If
End Sub


Thanks

SBY




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
Private Sub Workbook_Open() doesn't run Steve Starr Excel Discussion (Misc queries) 4 April 3rd 11 05:05 AM
Private Sub CommandButton1_Click() Bob Excel Discussion (Misc queries) 2 December 2nd 06 02:14 AM
Removal of Private Information PosseJohn Excel Discussion (Misc queries) 4 November 27th 05 10:33 PM
Common Private Sub Booker Excel Discussion (Misc queries) 1 November 15th 05 08:50 AM
Private sub Mark New Users to Excel 3 April 6th 05 03:36 PM


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