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
| Sub CopyToNewWbk()
Dim wks As Worksheet, rg As Range, wkb As Workbook
Set wks = Feuil1 ' la feuille ou sont les donnees
Set rg = wks.Range("1:1") ' la ligne ou il y a les titres de colonne
nom = "toto" ' nom a extraire
nCol = 2 ' colonne ou se trouve le nom
' extrait les lignes verifiant le critere
For i = 2 To wks.UsedRange.Rows.Count
If wks.Cells(i, nCol) Like nom Then
Set rg = Union(rg, wks.Range(i & ":" & i))
End If
Next i
' cree un nouveau classeur
Application.ScreenUpdating = False
Set wkb = Workbooks.Add
wkb.Windows(1).Visible = False
' copie vers le nouveau classeur
rg.Copy wkb.Worksheets(1).Cells(1, 1)
wkb.Windows(1).Visible = True
Application.ScreenUpdating = True
Set rg = Nothing
Set wks = Nothing
Set wkb = Nothing
End Sub |
Partager