Copy, Paste into different worksheet until last row and Print

Nick9010

New Member
Joined
Dec 31, 2019
Messages
2
Office Version
2016
Platform
Windows
Hi Members of MrExcel,

I am in need of help and unable to loop my sheet.

I have a workbook with 3 sheets

1) Input
2) Front
3) Printt

In the "Input" i have to columns G and H with Dates for the month

I am trying to paste the value from

Sheets("Input").Range("G2") into Sheet ("Printt").Range("A1") & Sheets("Input").Range("H2") into Sheet("Printt").Range("J1")

The "Printt" worksheet will then print and loop to the next following cell G3 and H3 until last row.

However, the code did not manage to pull information for the next row.

Hopefully someone can help point out my mistake.

THanks a lot. New to VBA




Below is my code:
VBA Code:
Sub Attendance()

Worksheets("Printt").Range("A1") = Worksheets("Input").Range("G2")
Worksheets("Printt").Range("J1") = Worksheets("Input").Range("H2")


Worksheets("Input").Range("G2").Select

Dim irow As Integer
irow = 2

Do Until IsEmpty(Cells(irow, 7))


Worksheets("Input").Range("H2").Select

Do Until IsEmpty(Cells(irow, 8))

        
'AutoPrint Macro

Worksheets("Front").PrintOut
Worksheets("Printt").PrintOut

'End AutoPrint
  
    irow = irow + 1
   Cells(irow, 7).Select
  
Loop
Loop

End Sub
 

Attachments

Some videos you may like

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

davesexcel

Well-known Member
Joined
Feb 26, 2006
Messages
815
You have a loop but are not doing anything in the loop but printing out the sheets.

I am not sure if you want to print after each loop or print after the loop.
I went with each loop as that is what was in your description.

VBA Code:
Sub Attendance()
    Dim sh As Worksheet, ws As Worksheet
    Dim Lstrw As Long, x

    Set ws = Sheets("Input")
    Set sh = Sheets("Printt")

    With ws
        Lstrw = .Cells(.Rows.Count, "G").End(xlUp).Row
        For x = 1 To Lstrw
            sh.Cells(1, "A").Value = .Cells(x + 1, "G").Value
            sh.Cells(1, "J").Value = .Cells(x + 1, "H").Value
            Worksheets("Front").PrintOut
            Worksheets("Printt").PrintOut

        Next x
        'AutoPrint Macro

    End With
End Sub
 

Nick9010

New Member
Joined
Dec 31, 2019
Messages
2
Office Version
2016
Platform
Windows
Hi Davesexcel,

Thanks for your help. The code worked, i thought the code that was in place was a loop format. I guess i was wrong.
 

Watch MrExcel Video

Forum statistics

Threads
1,099,096
Messages
5,466,633
Members
406,493
Latest member
Hazem Hassan

This Week's Hot Topics

Top