我正在尝试转置所有的列"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
发布于 2010-06-02 20:40:53
你可以试试这段代码,我已经在Excel2010上对超过10k个单元进行了测试:
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
https://stackoverflow.com/questions/2959083
复制相似问题