Macro that makes two pages for printing from one row

petars87

New Member
Joined
Sep 14, 2016
Messages
49
Hi people,

need your help with these:

i will like to make macro that copy data from sheet1 to sheet2(on this forum i learned how to do that) and also to format data on sheet2 like in example down:


sheet1:

A
B
C
D
E
F
G
H
I
J
1NAMECOL1COL2COL3COL4COL5COL6COL7COL8COL9
2Petar
1
2
3
4
5
6
7
8
9
3John
20
36
40
50
60
70
80
90
100
............

<tbody>
</tbody>

in sheet1 i can have n rows and from every row to make like in example down:

sheet2:


AB
1sheet1 A2sheet1 B2
2sheet1 C2sheet1 D2
3sheet1 E2sheet1 F2
4sheet1 G2sheet1 H2
5sheet1 I2sheet1 J2
6sheet1 A3sheet1 B3
7sheet1 C3sheet1 D3
8sheet1 E3sheet1 F3
9sheet1 G3sheet1 H3
10sheet1 I3sheet1 J3
.........

<tbody>
</tbody>
i will like to copy till last row in sheet1 and i will like to format every this set of data(every five rows in sheet2) to be ready for printing like document with two pages where first 3 rows is page 1(red color) and 4th and 5th row are page 2.

Thank you guys!
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Code:
Sub CollectData()
    Dim sourceSheet As Worksheet
    Dim destinSheet As Worksheet
    Dim lastRow As Long, r As Long, c As Integer
    Dim dR As Long, dC As Integer
    Application.ScreenUpdating = False
    Set sourceSheet = Sheets("Sheet1")
    Set destinSheet = Sheets("Sheet2")
    destinSheet.Cells.Clear
    lastRow = sourceSheet.Cells(Rows.Count, 1).End(xlUp).Row
    dR = 1
    dC = 1
    For r = 2 To lastRow
        For c = 1 To 10
            destinSheet.Cells(dR, dC) = sourceSheet.Cells(r, c)
            Select Case c
                Case 1 To 6
                    destinSheet.Cells(dR, dC).Font.Color = vbRed
                Case 7 To 10
                    destinSheet.Cells(dR, dC).Font.Color = vbGreen
            End Select
            If dC = 1 Then
                dC = 2
            Else
                dC = 1
                dR = dR + 1
            End If
        Next c
    Next r
End Sub

Sub PrintData()
    Dim printSheet As Worksheet
    Dim prArea As Range
    Set printSheet = Sheets("Sheet2")
    Set prArea = printSheet.Range("A1:B3")
    printSheet.PageSetup.PrintArea = prArea.Address
    Do
        printSheet.PrintOut
        If prArea.Rows.Count = 3 Then
            Set prArea = prArea.Offset(3).Resize(2, 2)
        Else
            Set prArea = prArea.Offset(2).Resize(3, 2)
        End If
        printSheet.PageSetup.PrintArea = prArea.Address
    Loop Until prArea.Cells(1, 1) = ""
End Sub
 
Upvote 0

Forum statistics

Threads
1,203,600
Messages
6,056,200
Members
444,850
Latest member
dancasta7

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