A Microsoft Excel forum. ExcelBanter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » ExcelBanter forum » Excel Newsgroups » Excel Worksheet Functions
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Ambiguous name detected: worksheet_change



 
 
Thread Tools Display Modes
  #1  
Old July 10th 12, 01:34 PM
FlesburgT FlesburgT is offline
Junior Member
 
First recorded activity by ExcelBanter: Jul 2012
Posts: 1
Default Ambiguous name detected: worksheet_change

I guess I have two different commands that are interfereing with each other. I have no clue if they can be combined or how to do that. Any help would be greatly appreciated. I've listed the code below

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

End Sub

Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("A")) Is Nothing Then
With Target
If .Column = 1 Then Cells(Rows.Count, .Column).End(xlUp).Offset(0, 1).Select
If .Column = 2 Then Cells(Rows.Count, .Column).End(xlUp).Offset(0, 1).Select
If .Column = 3 Then Cells(Rows.Count, .Column).End(xlUp).Offset(1, -2).Select
End With
End If

If Target.Cells.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("A1:A10000,B1:B10000,C1:C10000")) Is Nothing Then 'set your range here
ActiveSheet.Unprotect Password:=""
Target.Locked = True
ActiveSheet.Protect Password:=""
End If
End Sub


Private Sub Worksheet_Change(ByVal Target As Excel.Range)
'when entering data in a cell in Col A
On Error GoTo enditall
Application.EnableEvents = False
If Target.Cells.Column = 1 Then
N = Target.Row
If Me.Range("A" & N).Value <> "" Then
Me.Range("G" & N).Value = Now
End If
End If
enditall:
Application.EnableEvents = True
End Sub
Ads
  #2  
Old July 10th 12, 05:08 PM posted to microsoft.public.excel.worksheet.functions
GS[_2_]
external usenet poster
 
Posts: 2,241
Default Ambiguous name detected: worksheet_change

Procedure names MUST be unique. In this case you need to append the
code to execute in the 2nd instance of the _Change event to follow it's
counterpart in the 1st instance...

<snip>
Private Sub Worksheet_Change(ByVal Target As Range)

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

Select Case Target.Column
Case = 1
Cells(Rows.Count, .Column).End(xlUp).Offset(0, 1).Select
If Me.Range("A" & Target.Row).Value <> "" Then _
Me.Range("G" & Target.Row).Value = Now

Case = 2
Cells(Rows.Count, .Column).End(xlUp).Offset(0, 1).Select

Case = 3
Cells(Rows.Count, .Column).End(xlUp).Offset(1, -2).Select
End Select

If Target.Cells.Count > 1 Or _
Intersect(Target, Range("A1:C10000")) Is Nothing Then Exit Sub

'set your range here
ActiveSheet.Unprotect Password:=""
Target.Locked = True
ActiveSheet.Protect Password:=""
End Sub

...though I'm not clear on what it is you want to accomplish, it's
rarely necessary to select cells to act on them. Your approach seems
rather inefficient to me when there's better ways to accomplish what
this code does without having to select cells or toggle sheet
protection.

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #3  
Old January 9th 13, 12:12 PM posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1
Default Ambiguous name detected: worksheet_change

On Tuesday, July 10, 2012 9:38:45 PM UTC+5:30, GS wrote:
> Procedure names MUST be unique. In this case you need to append the
>
> code to execute in the 2nd instance of the _Change event to follow it's
>
> counterpart in the 1st instance...
>
>
>
> <snip>
>
> Private Sub Worksheet_Change(ByVal Target As Range)
>
>
>
> If Intersect(Target, Range("A")) Is Nothing Then Exit Sub
>
>
>
> Select Case Target.Column
>
> Case = 1
>
> Cells(Rows.Count, .Column).End(xlUp).Offset(0, 1).Select
>
> If Me.Range("A" & Target.Row).Value <> "" Then _
>
> Me.Range("G" & Target.Row).Value = Now
>
>
>
> Case = 2
>
> Cells(Rows.Count, .Column).End(xlUp).Offset(0, 1).Select
>
>
>
> Case = 3
>
> Cells(Rows.Count, .Column).End(xlUp).Offset(1, -2).Select
>
> End Select
>
>
>
> If Target.Cells.Count > 1 Or _
>
> Intersect(Target, Range("A1:C10000")) Is Nothing Then Exit Sub
>
>
>
> 'set your range here
>
> ActiveSheet.Unprotect Password:=""
>
> Target.Locked = True
>
> ActiveSheet.Protect Password:=""
>
> End Sub
>
>
>
> ..though I'm not clear on what it is you want to accomplish, it's
>
> rarely necessary to select cells to act on them. Your approach seems
>
> rather inefficient to me when there's better ways to accomplish what
>
> this code does without having to select cells or toggle sheet
>
> protection.
>
>
>
> --
>
> Garry
>
>
>
> Free usenet access at http://www.eternal-september.org
>
> ClassicVB Users Regroup!
>
> comp.lang.basic.visual.misc
>
> microsoft.public.vb.general.discussion


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Ambiguous name detected - help how fix? Chet Excel Programming 1 July 15th 09 09:09 PM
Excel 2007 ambiguous name detected:Worksheet_Change Steved Excel Programming 3 February 7th 08 10:03 PM
Ambiguous Name detected? davegb[_2_] Excel Programming 2 December 7th 07 05:09 PM
ambiguous name detected mark Excel Programming 4 February 4th 04 03:01 PM
Ambiguous Name Detected:~ jaf Excel Programming 0 September 12th 03 12:56 AM


All times are GMT +1. The time now is 08:35 AM.


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