Fusionner 2 macros identiques
Résolu
Drimo_8885
Messages postés
19
Date d'inscription
Statut
Membre
Dernière intervention
-
Drimo_8885 Messages postés 19 Date d'inscription Statut Membre Dernière intervention -
Drimo_8885 Messages postés 19 Date d'inscription Statut Membre Dernière intervention -
Rébonjour,
J'ai crée 2 userforms qui, séparément fonctionnent bien, mais j'aimerais les intégrer sur la même feuille mais en remplissant 2 cellules différentes de ma feuille :
M11 pour NOMENCLATURE et F23 pour Codecompte :
Ci-dessous les codes dans ma feuille principale pour chaque Userform.
Sauf qu'à l'exécution ça m'affiche "erreur de débogage Nom", j'ai compris que les 2 macros ont le même nom et ne peuvent être exécuter ensemble.
Je cherche donc une solution pour compiler les 2 et les faire fonctionner ensemble.
Merci par avance pour vos réponses !
Userform1:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("D11")) Is Nothing Then
If Target.Value = "Europe" Then
NOMENCLATURE.att1.Caption = 4
NOMENCLATURE.att2.Caption = 2
NOMENCLATURE.att3.Caption = 2
NOMENCLATURE.att4.Caption = 5
End If
If Target.Value = "Afrique" Then
NOMENCLATURE.att1.Caption = 7
NOMENCLATURE.att2.Caption = 2
NOMENCLATURE.att3.Caption = 2
NOMENCLATURE.att4.Caption = 2
End If
If Target.Value = "Asie" Then
NOMENCLATURE.att1.Caption = 4
NOMENCLATURE.att2.Caption = 2
NOMENCLATURE.att3.Caption = 2
NOMENCLATURE.att4.Caption = 5
End If
If Target.Value = "Amérique" Then
NOMENCLATURE.att1.Caption = 4
End If
NOMENCLATURE.code1.MaxLength = Val(NOMENCLATURE.att1.Caption)
NOMENCLATURE.code2.MaxLength = Val(NOMENCLATURE.att2.Caption)
NOMENCLATURE.code3.MaxLength = Val(NOMENCLATURE.att3.Caption)
NOMENCLATURE.code4.MaxLength = Val(NOMENCLATURE.att4.Caption)
NOMENCLATURE.code2.Visible = False
NOMENCLATURE.code3.Visible = False
NOMENCLATURE.code4.Visible = False
NOMENCLATURE.Show
End If
End Sub
___________________________________________________________________________________________________________
Userform 2 :
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("D11")) Is Nothing Then
If Target.Value = "Europe" Then
Codecompte.att1.Caption = 4
Codecompte.att2.Caption = 2
Codecompte.att3.Caption = 2
Codecompte.att4.Caption = 11
Codecompte.att5.Caption = 3
End If
If Target.Value = "Afrique" Then
Codecompte.att1.Caption = 7
Codecompte.att2.Caption = 2
Codecompte.att3.Caption = 2
Codecompte.att4.Caption = 11
Codecompte.att5.Caption = 3
End If
If Target.Value = "Asie" Then
Codecompte.att1.Caption = 4
Codecompte.att2.Caption = 2
Codecompte.att3.Caption = 2
Codecompte.att4.Caption = 11
Codecompte.att5.Caption = 3
End If
Codecompte.code1.MaxLength = Val(Codecompte.att1.Caption)
Codecompte.code2.MaxLength = Val(Codecompte.att2.Caption)
Codecompte.code3.MaxLength = Val(Codecompte.att3.Caption)
Codecompte.code4.MaxLength = Val(Codecompte.att4.Caption)
Codecompte.Code5.MaxLength = Val(Codecompte.att5.Caption)
Codecompte.code2.Visible = False
Codecompte.code3.Visible = False
Codecompte.code4.Visible = False
Codecompte.Code5.Visible = False
Codecompte.Show
End If
End Sub
J'ai crée 2 userforms qui, séparément fonctionnent bien, mais j'aimerais les intégrer sur la même feuille mais en remplissant 2 cellules différentes de ma feuille :
M11 pour NOMENCLATURE et F23 pour Codecompte :
Ci-dessous les codes dans ma feuille principale pour chaque Userform.
Sauf qu'à l'exécution ça m'affiche "erreur de débogage Nom", j'ai compris que les 2 macros ont le même nom et ne peuvent être exécuter ensemble.
Je cherche donc une solution pour compiler les 2 et les faire fonctionner ensemble.
Merci par avance pour vos réponses !
Userform1:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("D11")) Is Nothing Then
If Target.Value = "Europe" Then
NOMENCLATURE.att1.Caption = 4
NOMENCLATURE.att2.Caption = 2
NOMENCLATURE.att3.Caption = 2
NOMENCLATURE.att4.Caption = 5
End If
If Target.Value = "Afrique" Then
NOMENCLATURE.att1.Caption = 7
NOMENCLATURE.att2.Caption = 2
NOMENCLATURE.att3.Caption = 2
NOMENCLATURE.att4.Caption = 2
End If
If Target.Value = "Asie" Then
NOMENCLATURE.att1.Caption = 4
NOMENCLATURE.att2.Caption = 2
NOMENCLATURE.att3.Caption = 2
NOMENCLATURE.att4.Caption = 5
End If
If Target.Value = "Amérique" Then
NOMENCLATURE.att1.Caption = 4
End If
NOMENCLATURE.code1.MaxLength = Val(NOMENCLATURE.att1.Caption)
NOMENCLATURE.code2.MaxLength = Val(NOMENCLATURE.att2.Caption)
NOMENCLATURE.code3.MaxLength = Val(NOMENCLATURE.att3.Caption)
NOMENCLATURE.code4.MaxLength = Val(NOMENCLATURE.att4.Caption)
NOMENCLATURE.code2.Visible = False
NOMENCLATURE.code3.Visible = False
NOMENCLATURE.code4.Visible = False
NOMENCLATURE.Show
End If
End Sub
___________________________________________________________________________________________________________
Userform 2 :
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("D11")) Is Nothing Then
If Target.Value = "Europe" Then
Codecompte.att1.Caption = 4
Codecompte.att2.Caption = 2
Codecompte.att3.Caption = 2
Codecompte.att4.Caption = 11
Codecompte.att5.Caption = 3
End If
If Target.Value = "Afrique" Then
Codecompte.att1.Caption = 7
Codecompte.att2.Caption = 2
Codecompte.att3.Caption = 2
Codecompte.att4.Caption = 11
Codecompte.att5.Caption = 3
End If
If Target.Value = "Asie" Then
Codecompte.att1.Caption = 4
Codecompte.att2.Caption = 2
Codecompte.att3.Caption = 2
Codecompte.att4.Caption = 11
Codecompte.att5.Caption = 3
End If
Codecompte.code1.MaxLength = Val(Codecompte.att1.Caption)
Codecompte.code2.MaxLength = Val(Codecompte.att2.Caption)
Codecompte.code3.MaxLength = Val(Codecompte.att3.Caption)
Codecompte.code4.MaxLength = Val(Codecompte.att4.Caption)
Codecompte.Code5.MaxLength = Val(Codecompte.att5.Caption)
Codecompte.code2.Visible = False
Codecompte.code3.Visible = False
Codecompte.code4.Visible = False
Codecompte.Code5.Visible = False
Codecompte.Show
End If
End Sub
A voir également:
- Fusionner 2 macros identiques
- Supercopier 2 - Télécharger - Gestion de fichiers
- Comment fusionner des pdf sans logiciel - Guide
- Fusionner 2 cellules excel - Guide
- Fusionner 2 tableaux excel - Guide
- Fusionner mp3 - Télécharger - Audio & Musique
2 réponses
Bonjour,
comme ceci:
comme ceci:
Option Explicit Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Not Application.Intersect(Target, Range("M11")) Is Nothing Then 'code NOMENCLATURE.Show End If If Not Application.Intersect(Target, Range("F23")) Is Nothing Then 'code Codecompte.Show End If End Sub
Cela change tout!
voilà
Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Target, Range("D11")) Is Nothing Then If Target.Value = "Europe" Then NOMENCLATURE.att1.Caption = 4 NOMENCLATURE.att2.Caption = 2 NOMENCLATURE.att3.Caption = 2 NOMENCLATURE.att4.Caption = 5 Codecompte.att1.Caption = 4 Codecompte.att2.Caption = 2 Codecompte.att3.Caption = 2 Codecompte.att4.Caption = 11 Codecompte.att5.Caption = 3 ElseIf Target.Value = "Afrique" Then NOMENCLATURE.att1.Caption = 7 NOMENCLATURE.att2.Caption = 2 NOMENCLATURE.att3.Caption = 2 NOMENCLATURE.att4.Caption = 2 Codecompte.att1.Caption = 7 Codecompte.att2.Caption = 2 Codecompte.att3.Caption = 2 Codecompte.att4.Caption = 11 Codecompte.att5.Caption = 3 ElseIf Target.Value = "Asie" Then NOMENCLATURE.att1.Caption = 4 NOMENCLATURE.att2.Caption = 2 NOMENCLATURE.att3.Caption = 2 NOMENCLATURE.att4.Caption = 5 Codecompte.att1.Caption = 4 Codecompte.att2.Caption = 2 Codecompte.att3.Caption = 2 Codecompte.att4.Caption = 11 Codecompte.att5.Caption = 3 ElseIf Target.Value = "Amérique" Then NOMENCLATURE.att1.Caption = 4 End If NOMENCLATURE.code1.MaxLength = Val(NOMENCLATURE.att1.Caption) NOMENCLATURE.code2.MaxLength = Val(NOMENCLATURE.att2.Caption) NOMENCLATURE.code3.MaxLength = Val(NOMENCLATURE.att3.Caption) NOMENCLATURE.code4.MaxLength = Val(NOMENCLATURE.att4.Caption) NOMENCLATURE.code2.Visible = False NOMENCLATURE.code3.Visible = False NOMENCLATURE.code4.Visible = False Codecompte.code1.MaxLength = Val(Codecompte.att1.Caption) Codecompte.code2.MaxLength = Val(Codecompte.att2.Caption) Codecompte.code3.MaxLength = Val(Codecompte.att3.Caption) Codecompte.code4.MaxLength = Val(Codecompte.att4.Caption) Codecompte.Code5.MaxLength = Val(Codecompte.att5.Caption) Codecompte.code2.Visible = False Codecompte.code3.Visible = False Codecompte.code4.Visible = False Codecompte.Code5.Visible = False NOMENCLATURE.Show Codecompte.Show End If End Sub
voilà
Edit : j'ai pu résoudre le problème
J'ai peut-être oublié de préciser que j'ai une liste déroulante dans "D11" (Europe, Asie, Afrique et Amérique) et c'est selon le choix que je fais dans cette cellule que je remplis d'abord la cellule "M11" puis la cellule "F23".
J'ai essayé votre formule mais cela ne donne rien.
Bien à vous !