Petit probleme:
Un collegue à toucher à ma macro et elle ne fonctionne plus
Le message d'erreur me dit variable non définit
Voici la macro :
Option Explicit
Option Base 0
Public Sub Test()
Dim ws As Worksheet
Dim WSNew As Worksheet
Dim rng As Range, cell As Range
Dim Lrow As Long, FieldNum As Long
Dim objList As ListObject
Dim CCount As Long
Dim p As Integer
p = Input_Choix( _
Titre:="Choix colonne de découpage", _
texte:="Entrer le numéro de la colonne à découper")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error Resume Next
For Each ws In ActiveWorkbook.Worksheets
Next ws
On Error GoTo 0
Application.DisplayAlerts = True
Set rng = [A1]
Set objList = rng.ListObject
FieldNum = p
On Error Resume Next
ActiveSheet.ShowAllData
On Error GoTo 0
Set ws = Worksheets.Add(after:=Sheets(Sheets.Count))
With ws.Range("A1")
objList.ListColumns(FieldNum).Range.AdvancedFilter _
Action:=xlFilterCopy, _
CopyToRange:=.Range("A1"), _
Unique:=True
Lrow = .Cells(Rows.Count, "A").End(xlUp).Row
For Each cell In .Range("A2:A" & Lrow)
objList.Range.AutoFilter Field:=FieldNum, Criteria1:=cell.Value
CCount = 0
On Error Resume Next
CCount = objList.ListColumns(1).Range.SpecialCells(xlCellTypeVisible).Areas(1).Cells.Count
On Error GoTo 0
If CCount <> 0 Then
Set WSNew = Worksheets.Add(after:=Sheets(Sheets.Count))
WSNew.Name = cell.Value
objList.Range.SpecialCells(xlCellTypeVisible).Copy
With WSNew.Range("A1")
.PasteSpecial xlPasteColumnWidths
.PasteSpecial xlPasteValues
.PasteSpecial xlPasteFormats
Application.CutCopyMode = False
.Select
End With
End If
objList.Range.AutoFilter Field:=FieldNum
Next cell
On Error Resume Next
Application.DisplayAlerts = False
.Delete
Application.DisplayAlerts = True
On Error GoTo 0
End With
Application.ScreenUpdating = True
MsgBox ("Découpage réussi")
End Sub
Private Function Input_Choix(Titre As String, texte As String)
Input_Choix = Application.InputBox( _
texte, _
Titre, _
Type:=1)
End Function