views:

76

answers:

1

I am trying to Transpose all of column "B", but want to skip a line then grab the next 4 and paste them in the same column. How can I make this loop all of column "B" skipping every 5th line and change the range to the next open cell or "Range" automatically without manually typing each one individually?

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
A: 

you can try this code, I've tested it on Excel 2010 on more than 10k cells:

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
Cornelius
Thanks, I will give it a go and let you know...