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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| Public liste As Range
Public Sub essaioccurs()
Dim dercel As Range
With Sheets("Feuil3")
Set dercel = .Cells(.Rows.Count, 1).End(xlUp)
Set liste = .Range(.Cells(2, 1), dercel)
End With
Call Gestion_Feuilles("180520")
End Sub
Public Sub Gestion_Feuilles(occurs As String)
Dim i As Integer, n As Integer, nbcol As Integer
Dim f As Range, celcop As Range
Dim firstAddress As String
Dim Tablo() As Variant
Dim sh As Worksheet
Dim existe_feuil As Boolean
Application.ScreenUpdating = False
'Ligne de titre
With Sheets("Feuil3")
Set celcop = .Range("B1", .Cells(1, .Columns.Count).End(xlToLeft))
End With
'Nombre de données à alimenter = dimension 1 de la variable Tablo
nbcol = celcop.Columns.Count
'Test si la feuille existe
existe_feuil = False
For Each sh In Worksheets
If sh.Name = occurs Then
existe_feuil = True
Exit For
End If
Next sh
'Si la feuille n'existe pas, alors création de celle-ci avec nom et titres de colonnes adaptés
If existe_feuil = False Then
Sheets.Add Type:=xlWorksheet, After:=Sheets(Sheets.Count)
celcop.Copy
With ActiveSheet
.Paste Destination:=.Range("A1")
.Name = occurs
End With
Application.CutCopyMode = False
End If
'Alimentation de la variable Tablo
With liste
Set f = .Find(occurs, LookIn:=xlValues)
If Not f Is Nothing Then
firstAddress = f.Address
Do
n = n + 1
ReDim Preserve Tablo(1 To nbcol, 1 To n)
'Toutes les cellules de la ligne alimentent Tablo
For i = 1 To nbcol
Tablo(i, n) = f.Offset(0, i - numcol)
Next i
Set f = .FindNext(f)
Loop While Not f Is Nothing And f.Address <> firstAddress
End If
End With
'Alimentation de la feuille
With Sheets(occurs)
.Range("A2", .Range("A2").Offset(UBound(Tablo, 2) - 1, UBound(Tablo, 1) - 1)).Value = WorksheetFunction.Transpose(Tablo)
End With
'Réinitialisation de la variable Tablo
Erase Tablo
End Sub |
Partager