Modifier VBA pour scinder fichier en plusieurs onglets dans un seul fichier...

  • Initiateur de la discussion Initiateur de la discussion faber
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

faber

XLDnaute Nouveau
Bjr ,

j'ai récupéré de @mapomme du VBA (qui fonctionne à merveille) mais qui génère plusieurs classeurs.

Je voudrai que le fichier soit scindé dans 1 Classeur sur plusieurs Onglets

D'avance merci pour la modification du code (que je suis incapable de faire) 😀 !!!

le code est ci -dessous :

Sub découper()
Dim derlig&, dercol&, prefixe, nom$, n&, nbfic&
Dim F1, F2, i&, i1&, i2&, newclas, first

Application.ScreenUpdating = False
Set F1 = ThisWorkbook.Sheets("Feuil1")
Set F2 = ThisWorkbook.Sheets("Feuil2")
With F2
derlig = .Cells(.Rows.Count, "a").End(xlUp).Row
dercol = .Cells(1, .Columns.Count).End(xlToLeft).Column
nbfic = (derlig - 1) \ F1.Range("b3") - ((((derlig - 1) Mod F1.Range("b3"))) > 0)
End With
With F1
prefixe = ThisWorkbook.Path
If Right(prefixe, 1) <> "\" Then prefixe = prefixe & "\"
prefixe = prefixe & .Range("b1")
On Error Resume Next: MkDir prefixe: On Error GoTo 0
If Right(prefixe, 1) <> "\" Then prefixe = prefixe & "\"
prefixe = prefixe & .Range("b2")
prefixe = prefixe & "-"
End With

With F2
i1 = 2: i2 = i1 + F1.Range("b3") - 1
Set newclas = Workbooks.Add
Do
.Range("a1").Resize(, dercol).Copy newclas.Sheets(1).Range("a1")
.Range(.Cells(i1, "a"), .Cells(i2, dercol)).Copy newclas.Sheets(1).Range("a2")
newclas.Sheets(1).Range("a1").Resize(, dercol).EntireColumn.AutoFit
Application.DisplayAlerts = False
n = n + 1
Application.StatusBar = "fichier n° " & n & " / " & nbfic
nom = prefixe & Left("0000", 4 - Len("" & n)) & n & ".xlsx"
newclas.SaveAs Filename:=nom, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
Application.DisplayAlerts = True
If IsEmpty(first) Then first = nom
i1 = i1 + F1.Range("b3"): i2 = i2 + F1.Range("b3")
If i1 > derlig Then Exit Do
newclas.Sheets(1).UsedRange.Clear
Loop
End With
newclas.Close SaveChanges:=False
Application.StatusBar = False
MsgBox "Création de " & n & " fichiers terminée !" & vbLf & vbLf & _
"depuis " & vbLf & first & vbLf & vbLf & _
"jusqu'à " & vbLf & nom, vbInformation
End Sub
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

  • Question Question
Microsoft 365 Export données
Réponses
4
Affichages
503
  • Question Question
XL 2021 VBA excel
Réponses
4
Affichages
79
Réponses
2
Affichages
406
Réponses
7
Affichages
547
Réponses
3
Affichages
537
Réponses
5
Affichages
410
Retour