marcro copier coller

  • Initiateur de la discussion Initiateur de la discussion biba78
  • 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 !

biba78

XLDnaute Junior
Bonjour à tous, 🙂
j'ai besoin de votre aide.
pour mon fichier Excel, j'ai besoin d'une macro pour copier mes du 1er onglet les données importées d'une application dans un 2éme onglet en changeant l'ordre des colonnes.( voir l'exemple joint)
en vous remerciant par avance. 🙂
 

Pièces jointes

Bonjour, biba78, le Forum,

Attention aux espaces superflus dans le nom des onglets.

Un essai avec le code suivant.
Code:
Option Explicit
Sub Copier_coller()
    Dim a As Object, b As Object
    With Application: .ScreenUpdating = False: .Calculation = xlManual: .EnableEvents = False: End With
    Set a = Sheets("Extraction")
    Set b = Sheets("liste finale")
    b.Columns("a:h").Clear
    With a
        .Columns("f:f").SpecialCells(xlCellTypeVisible).SpecialCells(xlCellTypeConstants).Copy b.Range("a1")
        .Columns("h:h").SpecialCells(xlCellTypeVisible).SpecialCells(xlCellTypeConstants).Copy b.Range("b1")
        .Columns("g:g").SpecialCells(xlCellTypeVisible).SpecialCells(xlCellTypeConstants).Copy b.Range("c1")
        .Columns("a:e").SpecialCells(xlCellTypeVisible).SpecialCells(xlCellTypeConstants).Copy b.Range("d1")
    End With
    Cells.EntireColumn.AutoFit
    With Application: .EnableEvents = True: .Calculation = xlAutomatic: .ScreenUpdating = True: End With
End Sub
A bientôt 🙂
 
Bonjour à tous, 00 😉

Une autre macro
VB:
Sub a()
With Sheets("Extraction")
    .Columns("F:H").Copy Sheets("liste finale ").Range("A1")
    Application.CutCopyMode = False
    .Columns("A:E").Copy Sheets("liste finale ").Range("D1")
    Application.CutCopyMode = False
End With
End Sub
Même remarque que 00, il y a un espace dans le nom de la feuille Extraction.
Il faut donc le supprimer.

EDITION: je viens de voir que j'avais laissé l'espace dans le nom de la feuille liste finale.
Donc soit supprimer l'espace dans la macro et dans le nom de la feuille
soit ne rien faire
 
Bonjour, biba78, Staple1600 🙂, le Forum,
...elle ne fonctionne plus...
Parce que la présentation du dernier fichier déposé est différente...
VB:
Option Explicit
Sub Copier_coller_v2()
    Dim a As Object, b As Object
    With Application: .ScreenUpdating = False: .Calculation = xlManual: .EnableEvents = False: End With
    Set a = Sheets("Extraction")
    Set b = Sheets("liste finale")
    b.Columns("a:h").Clear
    With a
        .Rows("1:3").EntireRow.Hidden = True
        .Columns("f:f").SpecialCells(xlCellTypeVisible).SpecialCells(xlCellTypeConstants).Copy b.Range("a1")
        .Columns("h:h").SpecialCells(xlCellTypeVisible).SpecialCells(xlCellTypeConstants).Copy b.Range("b1")
        .Columns("g:g").SpecialCells(xlCellTypeVisible).SpecialCells(xlCellTypeConstants).Copy b.Range("c1")
        .Columns("a:e").SpecialCells(xlCellTypeVisible).SpecialCells(xlCellTypeConstants).Copy b.Range("d1")
        Rows("1:3").EntireRow.Hidden = False
    End With
    Cells.EntireColumn.AutoFit
    With Application: .EnableEvents = True: .Calculation = xlAutomatic: .ScreenUpdating = True: End With
End Sub
A bientôt 🙂
 
Sub Copier_coller_v2()
Dim a As Object, b As Object
With Application: .ScreenUpdating = False: .Calculation = xlManual: .EnableEvents = False: End With
Set a = Sheets("Extraction")
Set b = Sheets("liste finale")
b.Columns("a:h").Clear
With a
.Rows("1:3").EntireRow.Hidden = True
.Columns("f:f").SpecialCells(xlCellTypeVisible).SpecialCells(xlCellTypeConstants).Copy b.Range("a1")
.Columns("h:h").SpecialCells(xlCellTypeVisible).SpecialCells(xlCellTypeConstants).Copy b.Range("b1")
.Columns("g:g").SpecialCells(xlCellTypeVisible).SpecialCells(xlCellTypeConstants).Copy b.Range("c1")
.Columns("a:e").SpecialCells(xlCellTypeVisible).SpecialCells(xlCellTypeConstants).Copy b.Range("d1")
Rows("1:3").EntireRow.Hidden = False
End With
Cells.EntireColumn.AutoFit
With Application: .EnableEvents = True: .Calculation = xlAutomatic: .ScreenUpdating = True: End With
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

Réponses
3
Affichages
272
Réponses
10
Affichages
370
Retour