![](/img/trans.png)
[英]Copy and Paste Row and Columns(with formulas) and Paste down to the last row in VBA
[英]VBA copy & Paste loop from columns (B to G) to the last row of column A
Option Explicit
Sub stackColumns()
Const sCols As String = "B:G" ' Source Columns
Const sFirst As Long = 1 ' Source First Row
Const dCol As String = "A" ' Destination Column
Dim ws As Worksheet: Set ws = ActiveSheet ' adjust here
Dim srg As Range: Set srg = ws.Columns(sCols)
Dim dCell As Range: Set dCell = ws.Cells(ws.Rows.Count, dCol).End(xlUp)
If Not IsEmpty(dCell) Then
Set dCell = dCell.Offset(1)
End If
Dim crg As Range
Dim crCount As Long
Dim j As Long
For j = 1 To srg.Columns.Count
With srg.Columns(j)
crCount = .Cells(.Rows.Count).End(xlUp).Row - sFirst + 1
Set crg = .Resize(crCount).Offset(sFirst - 1)
End With
dCell.Resize(crCount).Value = crg.Value
Set dCell = dCell.Offset(crCount)
Next j
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.