Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error Resume Next: [zoneCopy].Delete: On Error GoTo 0
Select Case True
Case Target.Count > 1
Case Target = ""
Case Target.Column = Columns("B").Column
With Me.Shapes.AddShape(msoShapeRightArrow, Target.Left + 5, Target.Top, 20, Target.Height)
.Name = "zoneCopy"
.OLEFormat.Object.Interior.Color = RGB(255, 255, 204)
.OnAction = Me.CodeName & ".Copy_Zone"
End With
End Select
End Sub
Public Sub Copy_Zone()
Dim Target As Range, Source As Range, Zone As Range
Dim StartCell As Range, EndCell As Range
' Pour déterminer la plage d'application ( Zone ),
' on se base sur les bordures de séparation des lignes
' la ligne de début a la bordure supérieure <> Pointillé (xlHairline)
' la ligne de fin a la bordure inférieure <> Pointillé (xlHairline)
Set StartCell = Me.Shapes(Application.Caller).TopLeftCell
Do While (StartCell.Borders(xlEdgeTop).Weight = xlHairline)
Set StartCell = StartCell.Offset(-1)
Loop
Set EndCell = Me.Shapes(Application.Caller).TopLeftCell
Do While (EndCell.Borders(xlEdgeBottom).Weight = xlHairline)
Set EndCell = EndCell.Offset(1)
Loop
Set Zone = Range(StartCell, EndCell).Offset(, 8)
Me.Shapes(Application.Caller).TopLeftCell.Resize(, 2).Copy
Set Target = Zone.Find("", Zone.Cells(Zone.Rows.Count), xlValues, SearchDirection:=xlNext)
If Target Is Nothing Then Set Target = Zone.Find(0, Zone.Cells(Zone.Rows.Count), xlValues, SearchDirection:=xlNext)
If Not Target Is Nothing Then
Target.Resize(, 2).PasteSpecial Paste:=xlPasteValues
Else
MsgBox "Pas de cellules disponibles dans la zone " & Zone.Address, vbCritical
End If
End Sub