Decouper un fichier Excel

Fermé
r4944 Messages postés 122 Date d'inscription vendredi 2 octobre 2015 Statut Membre Dernière intervention 3 mars 2017 - 1 juin 2016 à 22:37
Bonjour,

Ce code là me permet de découper un fichier excel selon une colonne ''W''

j'ai eu un erreur à ce niveau :

sh.[AA].RemoveDuplicates Columns:=Array(1), Header:=xlYes


c'est bizarre par ce que le même code fonctionne et je l'ai utilisé dans d'autres fichiers


Option Explicit

Sub creation_fichiers()
Dim i As Integer
Dim sh, Dlg, plg
Application.ScreenUpdating = False
Application.DisplayAlerts = False

Set sh = Sheets(1)
Dlg = sh.Cells(Rows.Count, 1).End(xlUp).Row
Set plg = sh.Range("A5:W" & Dlg)
sh.Range("W6" & Dlg).Copy sh.[AA1]
sh.[AA].RemoveDuplicates Columns:=Array(1), Header:=xlYes
sh.[AC1] = sh.[W5]

For i = 2 To sh.Cells(Rows.Count, "AA").End(xlUp).Row
Workbooks.Add
sh.[AC2] = sh.Range("AA" & i)
plg.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=sh.Range("AC1:AC2"), CopyToRange:=ActiveWorkbook.Sheets(1).Range("A1:W1")

ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\" & sh.Range("AB" & i) & "-" & sh.Range("AA" & i) & ".xls", FileFormat:=xlExcel8

ActiveWorkbook.Close False
Next i
sh.[AA:AC].ClearContents
End Sub





A voir également: