1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| Private Sub Worksheet_Change(ByVal Target As Range)
Dim wks As Worksheet
Dim c As Range
Dim Cellule As Range
Dim rngDest As Range
Const NO_COLONNE As Long = 11
If Target.Cells.Count > 1 Then
For Each c In Target
If c.Column = NO_COLONNE Then
Set Cellule = c
Exit For
End If
Next c
Else
If Target.Column = NO_COLONNE Then
Set Cellule = Target
End If
End If
If Not Cellule Is Nothing Then
' copier la ligne entière à la suite des données dans
' la feuille portant le nom donnée dans la cellule.
If Cellule.Value = vbNullString Or IsNull(Cellule.Value) Then Exit Sub
On Error Resume Next
Set wks = Worksheets(Cellule.Value)
If wks Is Nothing Then
MsgBox "Impossible d'accéder à la feuille " & Cellule.Value & "!"
Err.Clear
Exit Sub
End If
On Error GoTo 0
Set rngDest = wks.UsedRange
If rngDest.Cells.Count > 1 Then
Set rngDest = wks.Cells(wks.UsedRange.Rows.Count + 1, 1)
End If
Application.ScreenUpdating = False
Cellule.EntireRow.Copy
wks.Paste Destination:=rngDest
Application.CutCopyMode = False
Application.ScreenUpdating = True
End If
End Sub |
Partager