Sub Swap()
'
colonnes = Array(5, 8, 9, 10, 15, 17, 18, 24)
If Selection.Count <> 2 Then
MsgBox "Ne sélectionner que 2 cellules à permuter"
Exit Sub
End If
Set trange = Selection
If trange.Areas.Count = 2 Then
If in_array(colonnes, trange.Areas(1).Column) And in_array(colonnes, trange.Areas(2).Column) Then
temp = trange.Areas(2)
trange.Areas(2) = trange.Areas(1)
trange.Areas(1) = temp
Else
GoTo fin
End If
Else
If in_array(colonnes, trange(1).Column) And in_array(colonnes, trange(2).Column) Then
temp = trange(1)
trange(1) = trange(2)
trange(2) = temp
Else
GoTo fin
End If
End If
Exit Sub
fin:
MsgBox "Zone interdite !"
End Sub
Function in_array(tableau, recherche)
'https://www.excel-pratique.com/fr/astuces_vba/recherche-tableau-array
in_array = False
For i = LBound(tableau) To UBound(tableau)
If tableau(i) = recherche Then 'Si valeur trouvée
in_array = True
Exit For
End If
Next
End Function