Problème macro pour Etirer une cellule

bapt0201

XLDnaute Nouveau
Bonjour,

Je suis bloqué sur une macro, je voudrais étirer la dernière cellule non vide de la colonne A à C jusqu'à la dernière cellule de la colonne D
J'ai réalisé une macro qui fonctionne mais seulement à partir de la cellule A1.
Le problème c'est que je ne sais pas comment prendre en compte la dernière cellule non vide de la colonne A à la place de la cellule A1

Voici ma macro et un fichier d'exemple qui j'espère vous permettra de m'aider à solutionner mon problème.


Sub Etirer_Formule()

Dim LastRw As Long

LastRw = Sheets("BDD 2019").Cells(Rows.Count, 4).End(xlUp).Row
Worksheets("BDD 2019").Range("A1:C" & LastRw).FillDown

End Sub


Je vous remercie par avance pour le temps consacré.
 

Pièces jointes

  • Test_macro.xlsm
    17.5 KB · Affichages: 10

vgendron

XLDnaute Barbatruc
Hello

un essai avec ceci
VB:
Sub Etirer_Formule()
    
    Dim LastRw As Long
    Dim LastRwA As Long
    LastRw = Sheets("BDD 2019").Range("D" & Rows.Count).End(xlUp).Row
    LastRwA = WorksheetFunction.CountA(Sheets("BDD 2019").Range("Tableau2").Columns(1)) 'Range("A" & Rows.Count).End(xlUp).Row
    Worksheets("BDD 2019").Range("A" & LastRwA).Resize(LastRw - LastRwA + 1, 3).FillDown
    
End Sub
 

mapomme

XLDnaute Barbatruc
Supporter XLD
Bonjour @bapt0201, @vgendron :),

Une autre piste:
VB:
Sub Etirer_Formule()
Dim FirstRow As Long, LastRow As Long
  With Sheets("BDD 2019")
    FirstRow = .Cells(.Rows.Count, "a").End(xlUp).Row
    If .Cells(FirstRow, "a") = "" Then FirstRow = .Cells(FirstRow, "a").End(xlUp).Row
    If FirstRow = 2 Then Exit Sub
    LastRow = .Cells(.Rows.Count, "d").End(xlUp).Row
    If .Cells(LastRow, "d") = "" Then LastRow = .Cells(LastRow, "d").End(xlUp).Row
    If LastRow > FirstRow Then .Range("A" & FirstRow & ":C" & LastRow).FillDown
  End With
End Sub
 

Pièces jointes

  • bapt0201-Test_macro- v1.xlsm
    21.1 KB · Affichages: 8
Dernière édition:

Discussions similaires

Membres actuellement en ligne

Statistiques des forums

Discussions
312 206
Messages
2 086 219
Membres
103 158
dernier inscrit
laufin