Dé-sélectionner

nadir****

XLDnaute Occasionnel
Bonjour
est-il possible de retirer une cellule (ou plusieurs cellules, ou une ligne ou une colonne) d'une plage déjà sélectionnée?
Il est facile de rajouter des cellules (avec la touche Ctrl) mais je ne sais pas faire le contraire.
Merci.

Nadir
 

Softmama

XLDnaute Accro
Re : Dé-sélectionner

Bonjour nadir***, Pierrot93

Effectivement CTRL permet de déselectionner une cellule, mais pas une zone (obligé de cliquer les cellules une par une)
Je t'ai donc fait une petite macro pour réparer ça :

VB:
Dim MemoSel As Range, NewSel As Range

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If MemoSel Is Nothing Then Set MemoSel = Selection: Exit Sub
If MemoSel.Address = Target.Address Then Exit Sub
Dim cel As Range
If Union(Target, MemoSel).Address = MemoSel.Address Then
    Application.EnableEvents = False
    Set NewSel = Nothing
    For Each cel In MemoSel
        If Intersect(cel, Target) Is Nothing Then
            If NewSel Is Nothing Then
                Set NewSel = cel
            Else
                Set NewSel = Union(NewSel, cel)
            End If
        End If
    Next
     NewSel.Select
    Application.EnableEvents = True
End If
Set MemoSel = Selection
End Sub

fichier exemple :
 

Pièces jointes

  • Déselectionner plage.xls
    26.5 KB · Affichages: 40
  • Déselectionner plage.xls
    26.5 KB · Affichages: 42
  • Déselectionner plage.xls
    26.5 KB · Affichages: 44

Softmama

XLDnaute Accro
Re : Dé-sélectionner

Re,

Un bug de Union(Plages) et Intersect(Plages) qui renvoient pas tjs les mêmes adresses de cellules fait que le fichier joint était parfois incorrect. Je l'ai corrigé ainsi :

VB:
Dim MemoSel As Range, NewSel As Range

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If MemoSel Is Nothing Then Set MemoSel = Selection: Exit Sub
If MemoSel.Address = Target.Address Then Exit Sub
Dim c As Range, cel As Range
For Each c In Target
    If Intersect(c, MemoSel) Is Nothing Then GoTo 1
Next c
  Application.EnableEvents = False
    Set NewSel = Nothing
    For Each cel In MemoSel
        If Intersect(cel, Target) Is Nothing Then
            If NewSel Is Nothing Then
                Set NewSel = cel
            Else
                Set NewSel = Union(NewSel, cel)
            End If
        End If
    Next
     NewSel.Select
  Application.EnableEvents = True
1 Set MemoSel = Selection
End Sub

Le fichier corrigé ici :
 

Pièces jointes

  • Déselectionner plage.xls
    37 KB · Affichages: 39
  • Déselectionner plage.xls
    37 KB · Affichages: 43
  • Déselectionner plage.xls
    37 KB · Affichages: 43

nadir****

XLDnaute Occasionnel
Re : Dé-sélectionner

Merci pour votre aide.
La touche Ctrl ne permet effectivement pas de dé-sélectionner une cellule (ou plus d'une). Dommage.
Je comprends la macro. En travaillant avec des union et des intersect de plages on y arrive, mais c'est un peu une galère.
Merci en tout cas pour ton aide Softmama.
A+
Nadir.
 

Discussions similaires

Réponses
6
Affichages
431

Statistiques des forums

Discussions
312 545
Messages
2 089 454
Membres
104 168
dernier inscrit
Make