XL 2016 Copier une plage d'une feuille Excel à une autre en tant que valeurs sans formatage

Dadi147

XLDnaute Occasionnel
Bonjour, je veux copier la feuille de données1 pleurant de la cellule ("a5:v" & lr) et la copier dans la feuille2 ("a9:v") La copie est toujours sous la dernière ligne avec des données feuille2 colonne A
 

Pièces jointes

  • COPY.xlsm
    13.2 KB · Affichages: 3
Solution
Bonjour Dadi147,
Les anciennes données doivent être conservées et les nouvelles copies en dessous
Alors utilisez :
VB:
Sub copie()
Dim P As Range, h&
With [Tableau1]
    With .ListObject.Range: .AutoFilter: .AutoFilter: End With 'si le tableau est filtré
    If Application.CountA(.Columns(1)) Then If .Cells(.Rows.Count, 1) = "" Then _
        Set P = .Rows(1).Resize(.Cells(.Rows.Count, 1).End(xlUp).Row - .Row + 1) Else Set P = .Cells
End With
With [Tableau334]
    With .ListObject.Range
        .AutoFilter: .AutoFilter 'si le tableau est filtré
        h = .Cells.Find("*", , xlValues, , xlByRows, xlPrevious).Row - .Row + 1
        If h = 1 Then .Rows(2) = "" Else If h < .Rows.Count Then .Rows(h + 1).Resize(.Rows.Count - h).Delete 'RAZ en dessous...

sylvanu

XLDnaute Barbatruc
Supporter XLD
Bonjour Dadi,
Un essai en PJ avec :
VB:
Sub copie()
tablo = Sheets("sh").[A5].CurrentRegion
N = [Tableau334].Rows.Count
With Sheets("sh1").Cells(N + 4, "A")
    .Resize(UBound(tablo, 1), UBound(tablo, 2)) = tablo
    .Delete
End With
End Sub
 

Pièces jointes

  • COPY (1).xlsm
    21.2 KB · Affichages: 3

sylvanu

XLDnaute Barbatruc
Supporter XLD
C'est plus explicite ainsi, ... et j'en étais loin. :)
Code:
Sub copie()
With Sheets("sh")
    DL = [Tableau1].Rows.Count
    For L = DL To 5 Step -1
        If .Cells(L, "A") <> "" Then Exit For
    Next L
    tablo = .Range("A5:V" & L + 1)
End With
N = [Tableau334].Rows.Count
With Sheets("sh1").Cells(N + 4, "A")
    .Resize(UBound(tablo, 1), UBound(tablo, 2)) = tablo
End With
End Sub
 

Pièces jointes

  • COPY 2.xlsm
    18.6 KB · Affichages: 1

job75

XLDnaute Barbatruc
Bonsoir Dadi147, sylvanu,

Une autre solution :
VB:
Sub copie()
Dim P As Range
With [Tableau1]
    With .ListObject.Range: .AutoFilter: .AutoFilter: End With 'si le tableau est filtré
    If Application.CountA(.Columns(1)) Then If .Cells(.Rows.Count, 1) = "" Then _
        Set P = .Rows(1).Resize(.Cells(.Rows.Count, 1).End(xlUp).Row - .Row + 1) Else Set P = .Cells
End With
With [Tableau334]
    With .ListObject.Range: .AutoFilter: .AutoFilter: End With 'si le tableau est filtré
    If .Rows.Count > 1 Then .Rows(2).Resize(.Rows.Count - 1).Delete xlUp 'RAZ
    If P Is Nothing Then .Rows(1) = "" Else P.Copy .Cells(1)
    .Parent.Activate 'facultatif
End With
End Sub
A+
 

Pièces jointes

  • COPY(1).xlsm
    20.8 KB · Affichages: 5

Dadi147

XLDnaute Occasionnel
Bonsoir Dadi147, sylvanu,

Une autre solution :
VB:
Sub copie()
Dim P As Range
With [Tableau1]
    With .ListObject.Range: .AutoFilter: .AutoFilter: End With 'si le tableau est filtré
    If Application.CountA(.Columns(1)) Then If .Cells(.Rows.Count, 1) = "" Then _
        Set P = .Rows(1).Resize(.Cells(.Rows.Count, 1).End(xlUp).Row - .Row + 1) Else Set P = .Cells
End With
With [Tableau334]
    With .ListObject.Range: .AutoFilter: .AutoFilter: End With 'si le tableau est filtré
    If .Rows.Count > 1 Then .Rows(2).Resize(.Rows.Count - 1).Delete xlUp 'RAZ
    If P Is Nothing Then .Rows(1) = "" Else P.Copy .Cells(1)
    .Parent.Activate 'facultatif
End With
End Sub
A+
Oui, mais lors de la recopie, les anciennes données sont copiées
Les anciennes données doivent être conservées et les nouvelles copies en dessous
 

job75

XLDnaute Barbatruc
Bonjour Dadi147,
Les anciennes données doivent être conservées et les nouvelles copies en dessous
Alors utilisez :
VB:
Sub copie()
Dim P As Range, h&
With [Tableau1]
    With .ListObject.Range: .AutoFilter: .AutoFilter: End With 'si le tableau est filtré
    If Application.CountA(.Columns(1)) Then If .Cells(.Rows.Count, 1) = "" Then _
        Set P = .Rows(1).Resize(.Cells(.Rows.Count, 1).End(xlUp).Row - .Row + 1) Else Set P = .Cells
End With
With [Tableau334]
    With .ListObject.Range
        .AutoFilter: .AutoFilter 'si le tableau est filtré
        h = .Cells.Find("*", , xlValues, , xlByRows, xlPrevious).Row - .Row + 1
        If h = 1 Then .Rows(2) = "" Else If h < .Rows.Count Then .Rows(h + 1).Resize(.Rows.Count - h).Delete 'RAZ en dessous
        If Not P Is Nothing Then P.Copy .Cells(h + 1, 1)
        .Parent.Activate 'facultatif
    End With
End With
End Sub
A+
 

Pièces jointes

  • COPY(2).xlsm
    21.3 KB · Affichages: 2

Discussions similaires

Membres actuellement en ligne

Statistiques des forums

Discussions
312 084
Messages
2 085 194
Membres
102 811
dernier inscrit
caroline29260