marcro copier coller

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

  • exemple.xlsx
    8.6 KB · Affichages: 45

DoubleZero

XLDnaute Barbatruc
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 :)
 

Staple1600

XLDnaute Barbatruc
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
 

DoubleZero

XLDnaute Barbatruc
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 :)
 

biba78

XLDnaute Junior
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
 

Discussions similaires

Réponses
6
Affichages
650

Statistiques des forums

Discussions
314 190
Messages
2 107 006
Membres
109 735
dernier inscrit
Mounskad