Как мне транспонировать с лимитом в 10 000 строк в Excel? - PullRequest
0 голосов
/ 02 июня 2010

Я пытаюсь переставить все столбцы "B", но хочу пропустить строку, затем взять следующие 4 и вставить их в тот же столбец. Как сделать так, чтобы весь цикл «B» пропускался через каждую 5-ю строку и автоматически изменял диапазон на следующую открытую ячейку или «Range», не вводя каждый из них по отдельности?

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 Ответ

1 голос
/ 03 июня 2010

вы можете попробовать этот код, я тестировал его в Excel 2010 на более чем 10 000 ячеек:

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
...