Autres Copier certaines colonnes

hamid43

XLDnaute Nouveau
Bonjour à tous,

SVP j'ai besoin d'un code vba qui sert à copier certaines colonnes de la feuille 1

vers la feuille 2 suivant le nom des champs de la feuille 2.

obs. les champs de la feuille2 sans variables

Merci d'avance pour votre aide,
 

Pièces jointes

  • copier certaines colonnes.xls
    91.5 KB · Affichages: 6

vgendron

XLDnaute Barbatruc
Hello
un essai avec ce code

VB:
Sub CopieCol()

Dim tabData() As Variant
Dim tabfin() As Variant

With Sheets("Feuille1")
    LastLine = .UsedRange.Rows.Count
    LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
    '.Range("A1").Resize(LastLine, LastCol).Select
    tabData = .Range("A1").Resize(LastLine, LastCol).Value
End With
With Sheets("Feuille2")
    LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
    ReDim tabfin(1 To LastLine, 1 To LastCol)
    For j = LBound(tabfin, 2) To UBound(tabfin, 2)
        tabfin(1, j) = .Cells(1, j)
    Next j
    
    For j = LBound(tabfin, 2) To UBound(tabfin, 2) 'pour chaque colonne de la feuille 2
        For k = LBound(tabData, 2) To UBound(tabData, 2) 'on la cherche dans tabdata
            If tabData(1, k) = tabfin(1, j) Then
                For i = LBound(tabData, 1) To UBound(tabData, 1)
                    tabfin(i, j) = tabData(i, k)
                Next i
                
            End If
        Next k
    Next j
    .Range("A1").Resize(UBound(tabfin, 1), UBound(tabfin, 2)) = tabfin
End With
End Sub
 

Discussions similaires

Statistiques des forums

Discussions
312 380
Messages
2 087 800
Membres
103 664
dernier inscrit
wolvi71