Copy, Paste into different worksheet until last row and Print

Nick9010

New Member
Joined
Dec 31, 2019
Messages
2
Office Version
  1. 2016
Platform
  1. 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

  • Cell snapshot.jpg
    Cell snapshot.jpg
    129.1 KB · Views: 6

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
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
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,212,931
Messages
6,110,745
Members
448,295
Latest member
Uzair Tahir Khan

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