IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

découpage lignes avec code VBA


Sujet :

Macros et VBA Excel

Mode arborescent

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Homme Profil pro
    aéronautique
    Inscrit en
    Juillet 2015
    Messages
    84
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : aéronautique
    Secteur : Transports

    Informations forums :
    Inscription : Juillet 2015
    Messages : 84
    Par défaut découpage lignes avec code VBA
    Bonjour,

    J'ai trouvé ce code VBA, aucun problème le code marche nickel.

    Le seul souci c'est qu'il prend que la colonne A, je voudrais qu'il prenne les colonnes A à F

    Merci pour votre aide

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    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
    Fichiers attachés Fichiers attachés

+ Répondre à la discussion
Cette discussion est résolue.

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo