Condividi:        

Problema "Nome ambiguo Worksheet_Change"

Vuoi potenziare i tuoi documenti Word? Non sai come si fa una macro in Excel? Devi creare una presentazione in PowerPoint?
Oppure sei passato a OpenOffice e non sei sicuro di come lavorare al meglio?

Moderatori: Anthony47, Flash30005

Problema "Nome ambiguo Worksheet_Change"

Postdi WCB » 07/03/19 13:01

Ciaooo a tuttii amici,
come mio solito stavo procedendo a scrivere una macro, ma ecco che appena chiudo l'editor e faccio per eseguirla mi fa ritornare sull'editor nuovamente e, all'altezza di Sub Private Worksheet_Change, evidenziato in giallo, esce una finestra con scritto "Nome ambiguo Worksheet_Change" :eeh:
Non vi nascondo che ho già un'altra Worksheet_Change nell'editor che opera in celle diverse rispetto alla seconda..
Ho cercato su internet le cause e, a quanto pare, questo problema succede nel momento in cui ci sta già un'altra worksheet change.
Non so che fare :?: avete qualche suggerimento?
Grazie mille anticipatamente :)
Questi sono i codici:

Codice: Seleziona tutto
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
 If Not Intersect(Target, Range("C13:D13")) Is Nothing Then
       Cells(17, 1).Formula = "N/A"
       Cells(18, 1).Formula = "N/A"
       Cells(19, 1).Formula = "N/A"
       Cells(20, 1).Formula = "N/A"
       Cells(21, 1).Formula = "N/A"
       Cells(17, 4).Formula = "N/A"
       Cells(18, 4).Formula = "N/A"
       Cells(19, 4).Formula = "N/A"
       Cells(20, 4).Formula = "N/A"
       Cells(21, 4).Formula = "N/A" ' uguale a Range("G2").Formula = "Visto"
ElseIf Not Intersect(Target, Range("A17:A21")) Is Nothing Then
       Cells(13, 3).Formula = "See below" ' uguale a Range("K3").Formula = "Visto"
       Cells(13, 4).Formula = "See below"
ElseIf Not Intersect(Target, Range("D17:D21")) Is Nothing Then
       Cells(13, 3).Formula = "See below" ' uguale a Range("K3").Formula = "Visto"
       Cells(13, 4).Formula = "See below"
End If
Application.EnableEvents = True
End Sub


'=========>>
Option Explicit
Option Compare Text

'--------->>
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim srcRng As Range
    Dim destRng As Range, destRng2 As Range, destRng3 As Range

    Const sIntervallo_Sorgente As String = "G10"             
    Const sIntervallo_Destinazione As String = "C28:C31"     
    Const sIntervallo_Destinazione2 As String = "D34:D43"     
    Const sIntervallo_Destinazione3 As String = "N10"       

    With Me
        Set srcRng = .Range(sIntervallo_Sorgente)
        Set destRng = .Range(sIntervallo_Destinazione)
        Set destRng2 = .Range(sIntervallo_Destinazione2)
        Set destRng3 = .Range(sIntervallo_Destinazione3)
    End With

    If Not Intersect(srcRng, Target) Is Nothing Then
        Select Case srcRng.Value
        Case "A", "B"
            destRng.Value = "N/A"
            Union(destRng2).ClearContents
        Case "B", "Update", "Clinician review"
            destRng2.Value = "0"
           
            destRng.ClearContents
        Case "C)"
         destRng3.Value = "A"
            Union(destRng).ClearContents
        Case Else
            Union(destRng, destRng2).ClearContents
        End Select
    End If
End Sub

"I computer sanno quando vai di fretta"
Excel 2016
Avatar utente
WCB
Utente Senior
 
Post: 101
Iscritto il: 09/01/19 17:52

Sponsor
 

Re: Problema "Nome ambiguo Worksheet_Change"

Postdi klingklang » 07/03/19 15:02

Ciao, per ogni foglio può esserci solo una routine WorkSheet_Change, quindi non hai altra scelta che integrare le due routine, procedendo con gli ElseIf Not Intersect... Is Nothing Then...
Enrico
Windows 7 + Office 2016 64bit / Windows 10 + Office 365 32/64bit
Avatar utente
klingklang
Utente Junior
 
Post: 97
Iscritto il: 23/11/18 15:01
Località: San Giovanni in Persiceto

Re: Problema "Nome ambiguo Worksheet_Change"

Postdi WCB » 07/03/19 16:25

Ciao,
ok ho "mischiato" le due macro e funzionano alla perfezione :D
Siccome che ora vorrei che altre celle facessero lo stesso "lavoro", ho provato a copiare il codice interessato con la variazione delle celle ma non funziona.. :cry:
Avresti qualche suggerimento a riguardo? Ti ringrazio per la disponibilità!
Questa è la parte del codice che interessa:
Codice: Seleziona tutto
 With Me

Set srcRng = .Range(sIntervallo_Sorgente)
Set destRng = .Range(sIntervallo_Destinazione)
Set destRng2 = .Range(sIntervallo_Destinazione2)
Set destRng3 = .Range(sIntervallo_Destinazione3)

On Error GoTo XIT
Application.EnableEvents = False
If Not Intersect(Target, Range("C13:D13")) Is Nothing Then
 Union(.Range("A17:A21"), .Range("D17:D21")).Value = "N/A"
 ElseIf Not Intersect(Target, Range("A17:A21")) Is Nothing Then
Me.Range("C13:D13").Value = "See below"
ElseIf Not Intersect(Target, Range("D17:D21")) Is Nothing Then
Me.Range("C13:D13").Value = "See below"
 End If
End With

Praticamente le altre celle che vorrei inserire avrebbero la stessa funzione di quelle sopra
"I computer sanno quando vai di fretta"
Excel 2016
Avatar utente
WCB
Utente Senior
 
Post: 101
Iscritto il: 09/01/19 17:52

Re: Problema "Nome ambiguo Worksheet_Change"

Postdi klingklang » 08/03/19 10:17

Ciao, pubblica il tuo listato (non funzionante) per intero, che solo da questo stralcio non capisco
Enrico
Windows 7 + Office 2016 64bit / Windows 10 + Office 365 32/64bit
Avatar utente
klingklang
Utente Junior
 
Post: 97
Iscritto il: 23/11/18 15:01
Località: San Giovanni in Persiceto

Re: Problema "Nome ambiguo Worksheet_Change"

Postdi WCB » 08/03/19 11:47

Ciao,
ti pubblico subito il codice per intero.
Grazie mille dell'aiuto!

Codice: Seleziona tutto
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim srcRng As Range

    Dim destRng As Range, destRng2 As Range, destRng3 As Range
   
    Const sIntervallo_Sorgente As String = "G10"                 <<<<<menù a tendina 
    Const sIntervallo_Destinazione As String = "C28:C31"     
    Const sIntervallo_Destinazione2 As String = "D34:D43"   
    Const sIntervallo_Destinazione3 As String = "N10"          <<<<<menù a tendina   'dovrei "duplicare" anche questa parte

    With Me

        Set srcRng = .Range(sIntervallo_Sorgente)
        Set destRng = .Range(sIntervallo_Destinazione)
        Set destRng2 = .Range(sIntervallo_Destinazione2)
        Set destRng3 = .Range(sIntervallo_Destinazione3)

        On Error GoTo XIT

        Application.EnableEvents = False

               If Not Intersect(Target, Range("C13:D13")) Is Nothing Then
            Union(.Range("A17:A21"), .Range("D17:D21")).Value = "N/A"
        ElseIf Not Intersect(Target, Range("A17:A21")) Is Nothing Then
            Me.Range("C13:D13").Value = "See below"
        ElseIf Not Intersect(Target, Range("D17:D21")) Is Nothing Then
            Me.Range("C13:D13").Value = "See below"
    End If
    End With

    If Not Intersect(srcRng, Target) Is Nothing Then

        Select Case srcRng.Value

        Case "a", "d", "e"
            destRng.Value = "N/A"
            Union(destRng2, destRng3).ClearContents

        Case "c"
            destRng2.Value = 0
            destRng3.Value = "b"
            destRng.Value = "N/A"

        Case "b"
            destRng2.Value = 0
            Union(destRng, destRng3).ClearContents

        Case Else
            Union(destRng, destRng2).ClearContents

        End Select
    End If

XIT:
    Application.EnableEvents = True
End Sub


le celle di destinazione naturalmente sono diverse da quelle sopra.
Grazie mille ancora
"I computer sanno quando vai di fretta"
Excel 2016
Avatar utente
WCB
Utente Senior
 
Post: 101
Iscritto il: 09/01/19 17:52

Re: Problema "Nome ambiguo Worksheet_Change"

Postdi klingklang » 08/03/19 12:57

WCB ha scritto:Siccome che ora vorrei che altre celle facessero lo stesso "lavoro", ho provato a copiare il codice interessato con la variazione delle celle ma non funziona.. :cry:
Avresti qualche suggerimento a riguardo? Ti ringrazio per la disponibilità!
Questa è la parte del codice che interessa:
Codice: Seleziona tutto
 With Me

Set srcRng = .Range(sIntervallo_Sorgente)
Set destRng = .Range(sIntervallo_Destinazione)
Set destRng2 = .Range(sIntervallo_Destinazione2)
Set destRng3 = .Range(sIntervallo_Destinazione3)

On Error GoTo XIT
Application.EnableEvents = False
If Not Intersect(Target, Range("C13:D13")) Is Nothing Then
 Union(.Range("A17:A21"), .Range("D17:D21")).Value = "N/A"
 ElseIf Not Intersect(Target, Range("A17:A21")) Is Nothing Then
Me.Range("C13:D13").Value = "See below"
ElseIf Not Intersect(Target, Range("D17:D21")) Is Nothing Then
Me.Range("C13:D13").Value = "See below"
 End If
End With

Praticamente le altre celle che vorrei inserire avrebbero la stessa funzione di quelle sopra


Non so se ho capito bene, ma puoi provare ad aggiungere altri range in questo modo:

Codice: Seleziona tutto
        If Not Intersect(Target, Union(Range("C13:D13"), Range("C10000:D10000"), Range("C99999:D99999"))) Is Nothing Then
            Union(.Range("A17:A21"), .Range("D17:D21")).Value = "N/A"


E' questo che cerchi?
Enrico
Windows 7 + Office 2016 64bit / Windows 10 + Office 365 32/64bit
Avatar utente
klingklang
Utente Junior
 
Post: 97
Iscritto il: 23/11/18 15:01
Località: San Giovanni in Persiceto

Re: Problema "Nome ambiguo Worksheet_Change"

Postdi WCB » 08/03/19 14:06

Grandeeee era quello che cercavooo :) :)
Invece per quanto riguarda questa parte:
Codice: Seleziona tutto
Const sIntervallo_Sorgente As String = "G10"                 
    Const sIntervallo_Destinazione As String = "C28:C31"     
    Const sIntervallo_Destinazione2 As String = "D34:D43"   
    Const sIntervallo_Destinazione3 As String = "N10"         

    With Me

        Set srcRng = .Range(sIntervallo_Sorgente)
        Set destRng = .Range(sIntervallo_Destinazione)
        Set destRng2 = .Range(sIntervallo_Destinazione2)
        Set destRng3 = .Range(sIntervallo_Destinazione3)


Dovrei solo aggiungere altre Destinazioni giusto?
Grazie mille ancora ;) ;)
"I computer sanno quando vai di fretta"
Excel 2016
Avatar utente
WCB
Utente Senior
 
Post: 101
Iscritto il: 09/01/19 17:52

Re: Problema "Nome ambiguo Worksheet_Change"

Postdi WCB » 08/03/19 14:43

Alla fine ho risolto aggiungendo altre Destinazioni e Sorgente.. Grazie mille per l'aiuto!!! 8) :D
"I computer sanno quando vai di fretta"
Excel 2016
Avatar utente
WCB
Utente Senior
 
Post: 101
Iscritto il: 09/01/19 17:52


Torna a Applicazioni Office Windows


Topic correlati a "Problema "Nome ambiguo Worksheet_Change"":


Chi c’è in linea

Visitano il forum: Nessuno e 44 ospiti