Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 41
Default Compile error: Ambigious name detected: Worksheet_Change **NEWBIE**

Hi all -
I am getting a Compile error: Ambigious name detected: Worksheet_Change

message when processing my code.

From reading various posts, I see that I can only use the

Worksheet_Change process once.

In my code below, how can I combine these procedures so I can make this
work? Thanks for your help!

'-----------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
'-----------------------------------------------------------------
Const WS_RANGE As String = "d5"

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
Range("c6:c24").Copy Range("c7:c25")
Range("c6").Value = Target.Value
End If

ws_exit:
Application.EnableEvents = True
End Sub

'-----------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
'-----------------------------------------------------------------
Const WS_RANGE As String = "q5"

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
Range("p6:p24").Copy Range("p7:p25")
Range("p6").Value = Target.Value
End If

ws_exit:
Application.EnableEvents = True
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Compile error: Ambigious name detected: Worksheet_Change **NEWBIE**

Hi
This should work:
Private Sub Worksheet_Change(ByVal Target As Range)
'-----------------------------------------------------------------
On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Target.Address = "D5" Then
Range("c6:c24").Copy Range("c7:c25")
Range("c6").Value = Target.Value
ElseIf Target.Address = "Q5" Then
Range("p6:p24").Copy Range("p7:p25")
Range("p6").Value = Target.Value
End If
Application.EnableEvents = True
ws_exit:
Application.EnableEvents = True
End Sub

I don't see the need for the EnableEvents or error code?

regards
Paul

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Compile error: Ambigious name detected: Worksheet_Change **NEWBIE**

Hi Paul,

If Not Target.Address = "D5" Then


I suspect that an exraneous 'Not' has crept into your code. Additionally, I
suspect that you intended "$D$5" rather than "D5".

Similarly, I assume that

ElseIf Target.Address = "Q5" Then


was intended as:

ElseIf Target.Address = "$Q$5" Then


I don't see the need for the EnableEvents or error code?


If events are not disabled, the copy operation(s) will re-trigger the
Worksheet_Change event and it is good practice to restore Application
settings in an error handler. Having, however, restored the Events setting
in the error handler, it is not necessarry to additionally restore Events
immediately prior to the error handler.


---
Regards,
Norman


wrote in message
ups.com...
Hi
This should work:
Private Sub Worksheet_Change(ByVal Target As Range)
'-----------------------------------------------------------------
On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Target.Address = "D5" Then
Range("c6:c24").Copy Range("c7:c25")
Range("c6").Value = Target.Value
ElseIf Target.Address = "Q5" Then
Range("p6:p24").Copy Range("p7:p25")
Range("p6").Value = Target.Value
End If
Application.EnableEvents = True
ws_exit:
Application.EnableEvents = True
End Sub

I don't see the need for the EnableEvents or error code?

regards
Paul



  #4   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 41
Default Compile error: Ambigious name detected: Worksheet_Change **NEWBIE**

This was great! Thanks Paul and Norman for your 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
Error message - Errors were detected while saving FILENAME Tim[_11_] Excel Discussion (Misc queries) 1 September 11th 08 03:44 PM
Compile error: Ambigious name detected: Worksheet_Change **NEWBIE** dan Excel Discussion (Misc queries) 1 May 26th 06 10:13 AM
VBAProject name compile error, not defined at compile time Matthew Dodds Excel Programming 1 December 13th 05 07:17 PM
Errors Detected Error Message Terri[_5_] Excel Programming 0 August 5th 04 09:46 PM


All times are GMT +1. The time now is 09:45 AM.

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"