[英]How do I Transpose with the 10,000 row limits of excel?
我正在嘗試對“ B”列的所有元素進行轉置,但是想跳過一行然后抓取下4個並將它們粘貼到同一列中。 我如何才能使“ B”列的所有循環都跳過第5行並自動將范圍更改為下一個打開的單元格或“范圍”,而無需手動分別鍵入每個范圍?
Range("B12:B16").Select
Selection.Copy
Sheets("Sheet2").Select
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
Range("B18:B22").Select
Selection.Copy
Sheets("Sheet2").Select
Range("A3").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
Range("B24:B28").Select
Selection.Copy
Sheets("Sheet2").Select
Range("A4").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
您可以嘗試使用此代碼,我已經在1萬多個單元格上的Excel 2010中對其進行了測試:
Sub SkipOnFive()
Dim inRow As Integer 'number of row in source worksheet
Dim outRow As Integer 'number of row in output worksheet
Dim outCol As Integer 'number of column in output worksheet
Dim strTemp As String
inRow = 1 'this is your start row on input sheet
outRow = 1 ' this is your start row on output sheet
Do
For outCol = 1 To 4
strTemp = Cells(inRow, 2).Value
Worksheets(2).Cells(outRow, outCol).Value = strTemp
inRow = inRow + 1
Next
outRow = outRow + 1
inRow = inRow + 1
Loop While strTemp <> vbNullString 'vbnullstring is kind of empty string, but it does not use any resources to create
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.