Copier coller jusqu’à cellule vide Excel
Bonjour,
Je souhaiterai faire un copié collé dans ma macro, mais le nombre de cellule n'est pas toujours pareil.
Je voudrais une amélioration, si possible, de ma formule (j'ai fait du bidouillage je l'avoue!)
Range("AD2:AD242").Select
Selection.Copy
Sheets("Fichier Synthèse").Select
Range("A3").Select
ActiveSheet.Paste
Sheets("Données").Select
Range("AE2:AE2242").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Fichier Synthèse").Select
Range("B3").Select
ActiveSheet.Paste
Sheets("Données").Select
Range("AI2:AI242").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Fichier Synthèse").Select
Range("C3").Select
ActiveSheet.Paste
Sheets("Données").Select
Range("AB2:AB242").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Fichier Synthèse").Select
Range("D3").Select
ActiveSheet.Paste
Si vous pouviez m'aider svp.
question sup si possible, j'ai fait mon code a l'aide de l'enregistreur de macro ^_^ la ligne "Sheets("Fichier Synthèse").Select" est elle utile? il me semble que c'est le changement d'onglet.
Merci
Dim Derligne As Long
Derligne = Range("H" & Rows.Count).End(xlUp).Row
Tafeuilledebase.Range("A" & i & ":U" & i).Copy Laoutuveuxlemettre.Range("A" & lgn)Essaie avec ces formules mais adapte
Question de noob (sorry) Que signifie ton A , U ET H ?? s'il te plait
Merci pour ta réponse en tout cas c'est cool!
Le H c'est la selection je suppose mais le reste je sais pas trop
Dim Derligne As Long
Derligne = Range("H" & Rows.Count).End(xlUp).Row
Tafeuilledebase.Range("A" & i & ":U" & i).Copy Laoutuveuxlemettre.Range("A" & lgn)
alors ca va chercher dans la colonne H la derniere cellule non vid
Ca commence a copier de la colonne A,derniere ligne, jusqu'a la colone U,derniere ligne, et ca colle dans ta deuxieme feuille a partir de A
the last one et j'te laisse tranquille l'amis
Dim Derligne As Long
Derligne = Range("AD" & Rows.Count).End(xlUp).Row
Données.Range("A" & i & ":U" & i).Copy FichierSynthèse.Range("A3")
J'ai foiré un truc quelques part! mais ou?
J'admet ne pas trop comprendre d'ou sorte les variables A et U puis je tiens a précisé que Données et FichierSynthèse sont des onglets d'un excel (au cas ou cela change quelque chose)
ps: il faut ensuite que j'envoie une fonction coller? ou c'est déjà inclus la dedans??
Sinon si tu peux me donner l'exemple directement ca serait parfait !
"Données" nom de mon onglet
Colonne AG jusqu'a cellule vide à copier/coller dans FichierSynthèse de A3 jusqu'a x.
Envoi ton fichier directement
Sub FichierSyntheseTest()
'
' FichierSyntheseTest Macro
' Génère un nouveau fichier
'
'
Range("A1").Select
ActiveCell.FormulaR1C1 = "Teddy"
Range("A2").Select
ActiveCell.FormulaR1C1 = "James"
Range("B2").Select
ActiveCell.FormulaR1C1 = "Barbie"
Range("C2").Select
ActiveCell.FormulaR1C1 = "Cedric"
Range("D2").Select
ActiveCell.FormulaR1C1 = "celia"
Range("E2").Select
ActiveCell.FormulaR1C1 = "edouard"
Range("F2").Select
ActiveCell.FormulaR1C1 = "kadie"
Range("A1:F1").Select
Application.WindowState = xlMaximized
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
Range("A2:F2").Select
Range("F2").Activate
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("A1:F2").Select
Range("F2").Activate
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent1
.TintAndShade = 0.599993896298105
.PatternTintAndShade = 0
End With
Range("A2:F2").Select
Range("F2").Activate
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Range("D4").Select
Columns("A:A").ColumnWidth = 16.14
Columns("B:B").ColumnWidth = 14.29
Columns("C:C").ColumnWidth = 13.57
Columns("C:C").ColumnWidth = 14.86
Columns("D:D").ColumnWidth = 31.71
Columns("D:D").ColumnWidth = 53
Columns("E:E").ColumnWidth = 30.29
Columns("E:E").ColumnWidth = 29.29
Columns("F:F").ColumnWidth = 14.71
Columns("D:D").ColumnWidth = 79
Columns("D:D").ColumnWidth = 85.86
Range("A3").Select
Sheets("Données").Select
Cells.Select
Range("T1").Activate
ActiveWorkbook.Worksheets("Données").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Données").Sort.SortFields.Add Key:=Range( _
"AB2:AB3979"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Données").Sort
.SetRange Range("A1:BE3979")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("AB6").Select
ActiveSheet.Range("$A$1:$BE$3978").AutoFilter Field:=28, Criteria1:="<>"
ActiveSheet.Range("$A$1:$BE$3978").AutoFilter Field:=33, Criteria1:= _
"=En attente de validation", Operator:=xlOr, Criteria2:="=Validé"
Range("AD2:AD242").Select
Selection.Copy
Sheets("Fichier Synthèse").Select
Range("A3").Select
ActiveSheet.Paste
Sheets("Données").Select
Range("AE2:AE2242").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Fichier Synthèse").Select
Range("B3").Select
ActiveSheet.Paste
Sheets("Données").Select
Range("AI2:AI242").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Fichier Synthèse").Select
Range("C3").Select
ActiveSheet.Paste
Sheets("Données").Select
Range("AB2:AB242").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Fichier Synthèse").Select
Range("D3").Select
ActiveSheet.Paste
Range("E3").Select
Sheets("Données").Select
Range("AC2:AC242").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Fichier Synthèse").Select
Range("E3").Select
ActiveSheet.Paste
Range("F3").Select
Sheets("Données").Select
Range("AG2:AG242").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Fichier Synthèse").Select
Range("F3").Select
ActiveSheet.Paste
Range("A3:F231").Select
Range("F231").Activate
Application.CutCopyMode = False
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Columns("F:F").ColumnWidth = 21.71
End Sub
c'est un fichier assez confidentiel malheureusement, jpeux t'explique ce que je dois faire a partir de ce code,
je dois prendre des informations à partir d'un onglet nommé "Données" sur mon classeur excel et en faire un nouvelle onglet (après avoir fait plusieurs opérations intermédiaires filtres etc.....) nommé "Fichier Synthèse"
le nouvelle onglet contient plusieurs colonne qui sont récupéré mais comme dit précédemment pour généralisé ma formule je souhaiterai faire un
exemple:
"commencé a AI2 et copier tout jusqu'a cellule non vide"
puis coller dans Fichier Synthèse
C'est cette partie la de mon code (elle revient 6 fois)
Range("AI2:AI242").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Fichier Synthèse").Select
Range("C3").Select
ActiveSheet.Paste
Voila j'espère avoir été claire c'est un peu complique comme cela!