Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim xvers As Range, Tablo As Range, xcell As Range, ligne As String, T, rep
Cancel = True
Set Tablo = Range(Range("b3"), Range("H" & Range("b" & Rows.Count).End(xlUp).Row))
If Not Intersect(Target, Tablo) Is Nothing Then
On Error Resume Next
Set xvers = Application.InputBox("Sélectionner une cellule de la ligne destination.", , , , , , , 8)
If Not xvers Is Nothing Then
On Error GoTo 0
If Not Intersect(xvers(1, 1), Tablo) Is Nothing Then
For Each xcell In Cells(xvers.Row, "c").Resize(1, 6)
ligne = ligne & xcell
Next xcell
If Trim(ligne) = "" Then
Cells(xvers.Row, "c").Resize(1, 6).Value = Cells(Target.Row, "c").Resize(1, 6).Value
Cells(Target.Row, "c").Resize(1, 6).ClearContents
Else
rep = MsgBox("Le lit de destination est déjà occupé ! " & vbLf & vbLf & _
"Voulez-vous intervertir de lit les deux patients ?", _
vbYesNo + vbDefaultButton2 + vbCritical)
If rep = vbYes Then
T = Cells(xvers.Row, "c").Resize(1, 6).Value
Cells(xvers.Row, "c").Resize(1, 6).Value = Cells(Target.Row, "c").Resize(1, 6).Value
Cells(Target.Row, "c").Resize(1, 6) = T
Else
MsgBox "Opération annulée"
End If
End If
End If
End If
End If
End Sub