Ceci est une page optimisée pour les mobiles. Cliquez sur ce texte pour afficher la vraie page.

probleme redondance

judoka0209

XLDnaute Occasionnel
bonjour je souhaiterai,
dans un premier temps, quand je suis sur la plage c6:cn11 que ca test que ce groupe
et dans un deuxieme temps, quand je suis sur la plage c15:cn20 que ca test que celui la mais plus l'autre

merci

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("C6:NC11")) Is Nothing Then Exit Sub
Dim macolonne As Range

Set macolonne = Range(Cells(6, Target.Column), Cells(11, Target.Column))
If Application.WorksheetFunction.CountIf(macolonne, "tt") + Application.WorksheetFunction.CountIf(macolonne, "tt") = 2 Or _
Application.WorksheetFunction.CountIf(macolonne, "tt") + Application.WorksheetFunction.CountIf(macolonne, "tt") = 2 Or _
Application.WorksheetFunction.CountIf(macolonne, "21") + Application.WorksheetFunction.CountIf(macolonne, "21ND") = 2 Or _
Application.WorksheetFunction.CountIf(macolonne, "21") + Application.WorksheetFunction.CountIf(macolonne, "10") = 2 Or _
Application.WorksheetFunction.CountIf(macolonne, "21") + Application.WorksheetFunction.CountIf(macolonne, "10nd") = 2 Or _
Application.WorksheetFunction.CountIf(macolonne, "21") + Application.WorksheetFunction.CountIf(macolonne, "33") = 2 Or _
Application.WorksheetFunction.CountIf(macolonne, "21") + Application.WorksheetFunction.CountIf(macolonne, "Rsec") = 2 Or _
Application.WorksheetFunction.CountIf(macolonne, "21") + Application.WorksheetFunction.CountIf(macolonne, "GTA") = 2 Or _
Application.WorksheetFunction.CountIf(macolonne, "21") + Application.WorksheetFunction.CountIf(macolonne, "SST") = 2 Or _
Application.WorksheetFunction.CountIf(macolonne, "21") + Application.WorksheetFunction.CountIf(macolonne, "FP") = 2 Or _
Application.WorksheetFunction.CountIf(macolonne, "21") + Application.WorksheetFunction.CountIf(macolonne, "35") = 2 Or _
Application.WorksheetFunction.CountIf(macolonne, "21") + Application.WorksheetFunction.CountIf(macolonne, "507i0") = 2 Or _
Application.WorksheetFunction.CountIf(macolonne, "21") + Application.WorksheetFunction.CountIf(macolonne, "AKPS") = 2 Or _
Application.WorksheetFunction.CountIf(macolonne, "21") + Application.WorksheetFunction.CountIf(macolonne, "AKSC") = 2 Or _
Application.WorksheetFunction.CountIf(macolonne, "21") + Application.WorksheetFunction.CountIf(macolonne, "41") = 2 Or _
Application.WorksheetFunction.CountIf(macolonne, "21") + Application.WorksheetFunction.CountIf(macolonne, "SEM") = 2 Or _
Application.WorksheetFunction.CountIf(macolonne, "21") + Application.WorksheetFunction.CountIf(macolonne, "41") = 2 Or _
Application.WorksheetFunction.CountIf(macolonne, "21") + Application.WorksheetFunction.CountIf(macolonne, "R Sec") = 2 Then
ALERTE.Show


ElseIf Application.WorksheetFunction.CountIf(macolonne, "10") + Application.WorksheetFunction.CountIf(macolonne, "10nd") = 2 Or _
Application.WorksheetFunction.CountIf(macolonne, "10") + Application.WorksheetFunction.CountIf(macolonne, "R Sec") = 2 Then
ALERTE.Show

End If

End Sub
 

vgendron

XLDnaute Barbatruc
Bonjour,

avec ton fichier exemple, ce serait plus facile à comprendre
selon la zone dans laquelle tu cliques (C6:CN11 ou C15:CN20) tu ne fais pas le meme test?

tu comptes quoi exactement?
Application.WorksheetFunction.CountIf(macolonne, "tt") + Application.WorksheetFunction.CountIf(macolonne, "tt") = 2
j'ai l'impression que tu calcules deux fois la meme chose..non?
 

vgendron

XLDnaute Barbatruc
et si tu fais quelque chose comme ca..

Dim macolonne As Range
If not Intersect(Target, Range("C6:NC11")) Is Nothing Then
set macolonne = Range(Cells(6, Target.Column), Cells(11, Target.Column))
elseif not Intersect (Target, Range("C15:NC20")) Is Nothing Then
set macolonne = Range(Cells(15, Target.Column), Cells(20, Target.Column))
else exit sub
--
-
-
-
 

judoka0209

XLDnaute Occasionnel
je le met comme ca

Private Sub Worksheet_Change(ByVal Target As Range)
Dim macolonne As Range
If Not Intersect(Target, Range("C6:NC11")) Is Nothing Then
Set macolonne = Range(Cells(6, Target.Column), Cells(11, Target.Column))
ElseIf Not Intersect(Target, Range("C15:NC20")) Is Nothing Then
Set macolonne = Range(Cells(15, Target.Column), Cells(20, Target.Column))
Else: Exit Sub

Set macolonne = Range(Cells(6, Target.Column), Cells(11, Target.Column))
 

Paf

XLDnaute Barbatruc
Bonjour judoka0209, vgendron

une approche similaire à celle de vgendron

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Application.Intersect(Target, Range("C6:H11,C15:H20")) Is Nothing Then Exit Sub

' initialisation lignes début et fin en fonction de la plage
If Target.Row < 15 Then
    LD = 6: LF = 11
Else
    LD = 15: LF = 20
End If

Set macolonne = Range(Cells(LD, Target.Column), Cells(LF, Target.Column))
'reste du code sans changement
End Sub

A+
 

judoka0209

XLDnaute Occasionnel
super ca marche par contre si je veux rajoute une plage je fais comme ca

Private Sub Worksheet_Change(ByVal Target As Range)

If Application.Intersect(Target, Range("C6:H11,C15:H20,c24:h29")) Is Nothing Then Exit Sub

' initialisation lignes début et fin en fonction de la plage
If Target.Row < 15 Then
LD = 6: LF = 11
Else
LD = 15: LF = 20
Else
LD = 24: LF = 29
End If
 

Paf

XLDnaute Barbatruc
Re,

par exemple:
Code:
If Target.Row < 15 Then
    LD = 6: LF = 11
ElseIf Target.Row > 20 Then
    LD = 24: LF = 29
Else
    LD = 15: LF = 20
End If

Si dans chaque plage il n'y a pas de cellules vides, on pourrait utiliser:
[edit 2: des lignes vides doivent séparer les plages, sinon currentregion ne les "verra" pas .
utiliser alors la proposition de Dranreb (lien edit ci dessous)]

Code:
With Target.CurrentRegion
LD = .Row
LF = LD + .Rows.Count - 1
End With

ce qui simplifierait le code s'il y a plus de 3 plages à traiter.

A voir sur un classeur joint

A+

Edit : Vous pourriez prévenir quand vous ouvrez une autre discussion pour cette même question !!!
http://excel-downloads.com/threads/probleme-if-else.20011695/
 
Dernière édition:

judoka0209

XLDnaute Occasionnel
oups desolé mais j'essaie de gener le moins de monde possible
ca marche pas car je dois gerer les plages individuellement ta premiere version fonctionnait

Private Sub Worksheet_Change(ByVal Target As Range)

If Application.Intersect(Target, Range("C6:H11,C15:H20")) Is Nothing Then Exit Sub

' initialisation lignes début et fin en fonction de la plage
If Target.Row < 15 Then
LD = 6: LF = 11
Else
LD = 15: LF = 20
End If

mais le soucis c'est que j'ai ca comme plage a gerer

Range("C6:NC11,C15:NC20,c24:NC29,C33:NC38,C42:NC47,C51:NC56"))

comment je peux faire
merci
 
Les cookies sont requis pour utiliser ce site. Vous devez les accepter pour continuer à utiliser le site. En savoir plus…