J'aimerais savoir comment intervertir deux cellules adjacentes suivant une certaine condition dans Excel (VBA). J'ai créé une commande, mais elle ne marche qu'avec un tableau de chiffre 2x2 et j'ai un chiffrier de 4x4. En bref, je veux pouvoir intervertir deux cellules advenant le cas où la cellule du haut,bas, à droite ou à gauche de la cellule selectionnée est = 0, les deux cellules se permuttent.
Voilà ce que j'ai fait :
Private Sub Worksheet_SelectionChange(ByVal target As Range)
Dim intA As Integer
If target.End(xlUp) = 0 Then 'en haut cellule active
intA = target.End(xlUp).Value 'transférer valeur en haut dans donnée temp
target.End(xlUp) = target.Value 'transférer la sélection dans cellule en haut
target = intA ' transéfrer donnée temp dans la sélection en cours
ElseIf target.End(xlDown) = 0 Then 'en bas cellule active
intA = target.End(xlDown).Value
target.End(xlDown) = target.Value
target = intA
ElseIf target.End(xlToLeft) = 0 Then 'à gauche cellule active
intA = target.End(xlToLeft).Value
target.End(xlToLeft) = target.Value
target = intA
ElseIf target.End(xlToRight) = 0 Then 'à droite cellule active
intA = target.End(xlToRight).Value
target.End(xlToRight) = target.Value
target = intA
End If
End Sub