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 44 45 46 47 48 49 50 51 52 53 54 55 56
|
Option Explicit
Sub generer_rapport_Noms()
Dim nom As String, data As Range, trans As Range
Dim e As Integer, c As Integer
'précautions
With Application
e = .EnableEvents
c = .Calculation
.EnableEvents = False
.ScreenUpdating = False
.Interactive = False
.Calculation = xlCalculationManual
End With
On Error GoTo fin
Sheets.Add 'ajoute une feuille pour les manipulations
Worksheets("données sources").Range("a1").CurrentRegion.Copy ActiveSheet.Range("a1")
Set trans = ActiveSheet.Range("a1").CurrentRegion
Set data = trans.Range(Cells(2, 1), Cells(trans.Rows.Count, trans.Columns.Count)) ' épargne la ligne d'en tête
nom = ActiveSheet.Name
trans.AutoFilter 1, data.Cells(2, 1)
Do
If trans.End(xlDown).Row <= trans.Rows.Count Then
Sheets.Add
ActiveSheet.Name = Mid(WorksheetFunction.Clean(data.Cells(2, 1)), 1, 30) 'précaution pour des noms contenant certains caractères
trans.CurrentRegion.Copy
ActiveSheet.Paste
data.SpecialCells(xlCellTypeVisible).EntireRow.Delete
End If
If trans.Rows.Count > 1 Then trans.AutoFilter 1, data.Cells(2, 1)
Loop Until trans.Rows.Count = 1
fin:
If Err Then MsgBox Err.Description: Err.Clear
Set trans = Nothing
Worksheets(nom).Delete
With Application
.ScreenUpdating = True
.Interactive = True
.EnableEvents = e
.Calculation = c
End With
End Sub |
Partager