Microsoft 365 Worksheet_Change(ByVal Target As Range)

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

tienou42

XLDnaute Nouveau
Bonjour,

Ca fonctionne mais c'est loin d'être parfait, par contre mon niveau est trop juste pour aller plus loin, petit problème : si je tape "3", ça me trouve un doublon sur la cellule qui contient "B3"

Pouvez vous m'aider ?

Code :
VB:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Dim Valeur
Dim xCell As Range
If flagFlux = True Then Exit Sub
If Not Intersect(Range("B2:B33,E2:E33,H2:H33,K2:K33,N2:N33"), Target) Is Nothing Then
flagFlux = True
For Each xCell In Intersect(Range("B2:B33,E2:E33,H2:H33,K2:K33,N2:N33"), Target).Cells
If Application.CountIf(Range("B2:N33"), xCell) > 1 Then
     MsgBox "Doublon !!!! :" & xCell
     Valeur = Target
     Range("B2:B33,E2:E33,H2:H33,K2:K33,N2:N33").Find(Valeur).Activate
End If
Next xCell
End If
flagFlux = False
End Sub

ps : ceci ne focntionne pas : "If Application.CountIf(Range("B2:N33"), xCell) > 1 Then" en ça : "If Application.CountIf(Range("B2:B33,E2:E33,H2:H33,K2:K33,N2:N33"), xCell) > 1 Then"
 
Solution
Bonjour,

Ca fonctionne mais c'est loin d'être parfait, par contre mon niveau est trop juste pour aller plus loin, petit problème : si je tape "3", ça me trouve un doublon sur la cellule qui contient "B3"

Pouvez vous m'aider ?

Code :
VB:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Dim Valeur
Dim xCell As Range
If flagFlux = True Then Exit Sub
If Not Intersect(Range("B2:B33,E2:E33,H2:H33,K2:K33,N2:N33"), Target) Is Nothing Then
flagFlux = True
For Each xCell In Intersect(Range("B2:B33,E2:E33,H2:H33,K2:K33,N2:N33"), Target).Cells
If Application.CountIf(Range("B2:N33"), xCell) > 1 Then
     MsgBox "Doublon !!!! :" & xCell
     Valeur = Target...
Bonjour,

Ca fonctionne mais c'est loin d'être parfait, par contre mon niveau est trop juste pour aller plus loin, petit problème : si je tape "3", ça me trouve un doublon sur la cellule qui contient "B3"

Pouvez vous m'aider ?

Code :
VB:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Dim Valeur
Dim xCell As Range
If flagFlux = True Then Exit Sub
If Not Intersect(Range("B2:B33,E2:E33,H2:H33,K2:K33,N2:N33"), Target) Is Nothing Then
flagFlux = True
For Each xCell In Intersect(Range("B2:B33,E2:E33,H2:H33,K2:K33,N2:N33"), Target).Cells
If Application.CountIf(Range("B2:N33"), xCell) > 1 Then
     MsgBox "Doublon !!!! :" & xCell
     Valeur = Target
     Range("B2:B33,E2:E33,H2:H33,K2:K33,N2:N33").Find(Valeur).Activate
End If
Next xCell
End If
flagFlux = False
End Sub

ps : ceci ne focntionne pas : "If Application.CountIf(Range("B2:N33"), xCell) > 1 Then" en ça : "If Application.CountIf(Range("B2:B33,E2:E33,H2:H33,K2:K33,N2:N33"), xCell) > 1 Then"
Bonjour,
S'il s'agit d'avoir un message s'il y a doublon
Essaye ceci
VB:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim C As Range
    If Target.Count > 1 Then Exit Sub
    If Intersect(Range("B2:B33,E2:E33,H2:H33,K2:K33,N2:N33"), Target) Is Nothing Then Exit Sub
    If Target = "" Then Exit Sub
    For Each C In Range("B2:B33, E2:E33, H2:H33, K2:K33, N2:N33")
        If Target.Address <> C.Address And C = Target Then
            MsgBox "Doublon de: " & Target & vbLf & "En " & C.Address, vbInformation, "Information"
        End If
    Next
End Sub
 
Dernière édition:
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

  • Question Question
Microsoft 365 worksheet_change
Réponses
29
Affichages
250
  • Question Question
Microsoft 365 Probléme VBA
Réponses
8
Affichages
233
Réponses
14
Affichages
371
Retour