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

Programmation système Discussion :

Programation VBA excel


Sujet :

Programmation système

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2014
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Dordogne (Aquitaine)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Service public

    Informations forums :
    Inscription : Mars 2014
    Messages : 1
    Points : 1
    Points
    1
    Par défaut Programation VBA excel
    bonjour a toutes et á tous

    Novice du premier degré en programation VBA sous Excel, j'ai rassemblé plusieurs informations qui m'ont permises d'écrire un code d'importation
    et de consiolidation de plusieurs feuilles excel.
    Le code semble fonctionner, mais je n'arrive pas a diminuer le nombre de lignes importées par feuille (au alentour de 20.000) ou en réalité je dois en avoir
    au maximum 500!!!
    Si un de vous pouviez m'aider, je vous en serai trés reconnaissant
    Par la même occasion, si vous penser qu'il soit possible d'optimiser (j'en suis certain) l'écriture de ce programme, ne vous gêner pas.

    Par avance merci pour votre retour.

    Sheets("3. Prospecção").Select
    Sheets("3. Prospecção1").Visible = True
    Sheets("3. Prospecção1").Select
    Range("A1").Select
    Cells.Delete
    Range("b2") = "1. Empresa"
    Range("c2") = "2. Nome da Unidade"
    Range("d2") = "3. Contato"
    Range("e2") = "4. Telefone"
    Range("f2") = "5. Vendedor Responsável"
    Range("g2") = "6. Área de Venda"
    Range("h2") = "7. Serviço Oferecido"
    Range("i2") = "8. Categoria de Serviço"
    Range("J2") = "9. Valor do Negócio"
    Range("K2") = "10. Primeiro Contato"
    Range("L2") = "Contato Realizado"
    Range("M2") = "Reunião 1"
    Range("n2") = "Reunião 2"
    Range("o2") = "Negociação"
    Range("p2") = "Ganho"
    Range("q2") = "Perdido"
    Range("r2") = "12. Último Contato"
    Range("s2") = "13. Motivo da Perda"
    Range("b22").Font.Bold = True

    ' Parcours de tous les fichiers
    ' ------------------------------
    ChDir "C:\GRSA\Analise Mercado DOR\Import"
    ClasseurRegional = Dir("C:\GRSA\Analise Mercado DOR\Import\*.xlsx")
    While Len(ClasseurRegional) > 0
    Workbooks.Open ClasseurRegional
    Sheets("3. Prospecção").Select
    AvantDerniereLigne = ActiveSheet.UsedRange.Rows.Count - 1
    Range("b8:s" & AvantDerniereLigne).Copy
    Workbooks("PipeLine DOR.xlsm").Activate
    Sheets("3. Prospecção1").Select
    DebutNomFichier = ActiveSheet.UsedRange.Rows.Count + 2
    Range("B" & ActiveSheet.UsedRange.Rows.Count + 2).Select
    ActiveSheet.Paste
    Range("A" & DebutNomFichier & ":A" & ActiveSheet.UsedRange.Rows.Count) = ClasseurRegional
    Workbooks(ClasseurRegional).Close
    ClasseurRegional = Dir
    Wend
    Columns("A:A").Replace ".xlsx", ""
    Cells.EntireColumn.AutoFit
    Range("A1").Select
    Sheets("3. Prospecção").Select
    Range("B8:S1000000").Select
    Selection.ClearContents
    Sheets("3. Prospecção1").Select
    Range("B2").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    ActiveWorkbook.Worksheets("3. Prospecção1").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("3. Prospecção1").Sort.SortFields.Add Key:=Range( _
    "F3:F147903"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
    xlSortNormal
    With ActiveWorkbook.Worksheets("3. Prospecção1").Sort
    .SetRange Range("B2:S147903")
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
    End With
    Range("A1").Select
    Range("B3:S9500").Select
    Selection.Copy
    Sheets("3. Prospecção").Select
    Range("B8").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Sheets("3. Prospecção1").Select
    ActiveWindow.SelectedSheets.Visible = False
    Sheets("3. Prospecção").Select
    Range("A1").Select
    End Sub

  2. #2
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 519
    Points
    41 519
    Par défaut


    La grosse colonne de Range(Selection, Selection.End(xlDown)).Select est sûrement remplaçable par un truc d'une seule ligne. Je ne connais pas les propriétés de Range, mais je suis sûr que tu peux ajouter X lignes à une Range sans avoir là le faire ligne par ligne.
    De plus, la propriété Selection ne retourne-t-elle pas elle-même une Range?
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  3. #3
    Inactif  

    Homme Profil pro
    Développeur .NET
    Inscrit en
    Janvier 2012
    Messages
    4 904
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Finance

    Informations forums :
    Inscription : Janvier 2012
    Messages : 4 904
    Points : 10 168
    Points
    10 168
    Billets dans le blog
    36
    Par défaut
    Bonjour,

    Pour ajouter 10 lignes, le plus simple c'est d'enregistrer une macro en insérant 10 lignes d'un coup. Vite fait:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    Sub Macro1()
    '
    
        Range("A1:A10").Select
        Selection.EntireRow.Insert
    End Sub
    Quant à savoir pourquoi tu importes trop de lignes, ma boule de cristal est cassée.

    P.S Le forum VBA Excel est au bout de ce lien
    À ma connaissance, le seul personnage qui a été diagnostiqué comme étant allergique au mot effort. c'est Gaston Lagaffe.

    Ô Saint Excel, Grand Dieu de l'Inutile.

    Excel n'a jamais été, n'est pas et ne sera jamais un SGBD, c'est pour cela que Excel s'appelle Excel et ne s'appelle pas Access junior.

Discussions similaires

  1. [VBA-Excel,VB6,Fichier texte]enregistrer un classeur excel..
    Par Tarul dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 11/01/2005, 13h09
  2. [vba-excel] Le temps de fermeture trop court ?
    Par Damsou dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 11/01/2005, 10h03
  3. [VBA-Excel]
    Par Damsou dans le forum Macros et VBA Excel
    Réponses: 6
    Dernier message: 05/01/2005, 10h17
  4. [VBA EXCEL] Réduire/Agrandir UserForms
    Par Fench dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 06/11/2003, 16h02
  5. [VBA Excel] Effacer rapidement une feuille
    Par Invité dans le forum Macros et VBA Excel
    Réponses: 4
    Dernier message: 24/10/2002, 13h12

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