Loop through sheet 1 and copy/paste transpose every 12 rows

hakeem26

New Member
Joined
Dec 24, 2015
Messages
3
Good Day to all,
I am new to VBA, I have Budget data in sheet1 as follow

ABCDEFGHIJKLMNOPQRS
1CompDivAcctCCPGDimCURRJanFebMarAprMayJunJulAugSepOctNovDec
29051014100UC000526LU1USD525853635756535957636972
39051024215UC526313LO1USD141716191223171615121921

<tbody>
</tbody>

I want to copy this into sheet 2 using loop because sheet 1 is so long, I record the following code.
****** id="cke_pastebin" style="position: absolute; top: 89.6px; width: 1px; height: 1px; overflow: hidden; left: -1000px;">
905

<tbody>
</tbody>

Code:
Sub Macro8()
'
' Macro8 Macro
'


'
    Sheets("B").Select
    Range("H2:S2").Copy
    Sheets ("BM3"), Range("L1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=True
    Application.CutCopyMode = False
    Selection.Copy
    Range("M1").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Sheets("B").Select
    Range("H1:S1").Select
    Selection.Copy
    Sheets("BM3").Select
    Range("N1").Select
    Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True
    Sheets("B").Select
    Range("A2:F2").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("BM3").Select
    Range("A1:A12").Select
    ActiveSheet.Paste
    ''''''''''''''''''''''''''''''''''
    Sheets("B").Select
    Range("H3:S3").Select
    Selection.Copy
    Sheets("BM3").Select
    Range("L13").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=True
    Application.CutCopyMode = False
    Selection.Copy
    Range("M13").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Sheets("B").Select
    Range("$H$1:$S$1").Select
    Selection.Copy
    Sheets("BM3").Select
    Range("N13").Select
    Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=True
    Sheets("B").Select
    Range("A3:F3").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("BM3").Select
    Range("A13:A24").Select
    ActiveSheet.Paste
    ''''''''''''''''''''''''''''''''''
    Sheets("B").Select
    Range("H4:S4").Select
    Selection.Copy
    Sheets("BM3").Select
    Range("L25").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=True
    Application.CutCopyMode = False
    Selection.Copy
    Range("M25").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Sheets("B").Select
    Range("$H$1:$S$1").Select
    Selection.Copy
    Sheets("BM3").Select
    Range("N25").Select
    Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=True
    Sheets("B").Select
    Range("A4:F4").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("BM3").Select
    Range("A25:A36").Select
    ActiveSheet.Paste
    ''''''''''''''''''''''''''''''''''
End Sub


Help please
 
Last edited by a moderator:

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Can you show how is the final result is sheet2 ?
 
Upvote 0
ABCDEFGHIJKLMN
9051014100UC000526LU15252Jan
9051014100UC000526LU15858Feb
9051014100UC000526LU15353Mar

<tbody>
</tbody>
 
Last edited:
Upvote 0
The currency "USD" don't appear anymore ???
because sheet 1 is so long
you mean too large, because the new sheet will have a lot of more rows !!!
In new sheet , column L and M are identical ???
 
Upvote 0
Perhaps next code ...!

Code:
Option Explicit


Sub Treat()
Const Ws1N = "Sheet1"
Const Ws2N = "Sheet2"
Const Sepa = "/"
Dim WS1 As Worksheet, WS2 As Worksheet
Dim I  As Integer, II As Integer, J As Integer


    Set WS1 = Sheets(Ws1N): Set WS2 = Sheets(Ws2N)
    Application.ScreenUpdating = False
    With WS2
        .Cells.ClearContents
        .Cells(1, 1).Resize(1, 14) = Array("Comp", "Div", "Acct", "CC", "PG", _
               "Dim", "", "", "", "", "", "--", "--", "Month")
    End With
    II = 1
    With WS1
        For I = 2 To .Cells(Rows.Count, 1).End(3).Row
            For J = 8 To 19
                II = II + 1
                Range(.Cells(I, 1), .Cells(I, 6)).Copy WS2.Cells(II, 1)
                WS2.Cells(II, 12) = WS1.Cells(I, J)
                WS2.Cells(II, 13) = WS1.Cells(I, J)
                WS2.Cells(II, 14) = WS1.Cells(1, J)
            Next J
        Next I
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,552
Messages
6,131,320
Members
449,644
Latest member
tbhoola

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top