2016-07-21 158 views
0

我的問題是:如何在G列的調換後四排成不同的列?移調從行到列(VBA)

我通常使用靜態代碼:

Worksheets("Sheet8").Range("A1:A5").Copy 
Worksheets("Sheet9").Range("A1").PasteSpecial Transpose:=True 

不過,這並不讓我留在同一張紙上。

所以我想它的代碼相結合:

Dim r As Range, N As Long 
N = Cells(Rows.Count, "A").End(xlUp).Row 
Set r = Cells(N, 1).EntireRow 

r.Copy 
Cells(N + 1, 1).PasteSpecial Transpose:=True 
r.Delete 

之前 enter image description here

enter image description here

之後的任何幫助表示讚賞

+0

你的問題有點令人困惑:你在ColA或ColG上工作嗎? –

+0

對不起,確實很混亂。我正在使用ColG - ColA是另一個代碼的片段 – pdx

回答

1

未測試:

Dim c As Range, v 

'find last-used cell in ColG 
Set c = Cells(Rows.Count, "G").End(xlUp) 

With c.offset(-3,0) 'starting with the cell 3 rows above the last-used cell... 
    v = .resize(4,1).value  'get the value of the 4-row/1-col range below 
    .resize(4,1).clearcontents '...then clear that range 
    .resize(1,4).value = Application.Transpose(v) 'place the values in a row 
End with 
+0

工作得很好,謝謝!感謝你能寫下你的代碼的快速解釋! – pdx