VBA Copy, Paste, Print, Loop next row

chris186h

Board Regular
Joined
Mar 18, 2015
Messages
111
Hello All. I have a sheet called 'Log'. Row 1 contains the Titles which do not need to have the macro run on.
Cells A:I have the data.
I am trying to get the code to copy the row, Paste it to 'Print out'A1
Print the document the return to the log sheet and repeat the code on the next row until there is nothing left to copy. The below code is what i have so far although it doesnt seam to paste the values and it always prints the titles.
Any help would be very appreciated
Thankyou

Code:
Sub PrintLogs()
    Dim lastRow As Long, i As Long
    Dim ws As Worksheet
    Set ws = Sheets("Log")
    lastRow = ws.Range("A" & Rows.Count).End(xlUp).Row
    With ws
        For i = 1 To lastRow
            If Len(Trim(.Range("A" & i).Value)) <> 0 Then _
            .Range("J" & i).Formula = "Printed"
 ActiveCell.EntireRow.Select
       Selection.Copy
    Sheets("Print-Out").Select
    Range("A1").Activate
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
        IgnorePrintAreas:=False
             Sheets("Log").Select
            
            
            
        Next i
    End With
End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Try the amendments below (untested so definitely test on a copy of your data).

Code:
Sub PrintLogs()
    Dim lastRow As Long, i As Long
    Dim ws As Worksheet
    Set ws = Sheets("Log")
    lastRow = ws.Range("A" & Rows.Count).End(xlUp).Row
    With ws
        For i = 2 To lastRow
            If Len(Trim(.Range("A" & i).Value)) <> 0 Then _
            .Range("J" & i).Formula = "Printed"
 .Range("A" & i).EntireRow.Copy
    Sheets("Print-Out").Range("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Sheets("Print-Out").PrintOut Copies:=1, Collate:=True, _
        IgnorePrintAreas:=False
        Next i
    End With
End Sub
 
Upvote 0
Your welcome (and amazed I didn't miss something :ROFLMAO:).
 
Upvote 0
Hi Mark858,

Hoping you can help me to expand this to work for me because I'm at a loss. I'm trying to do something similar, however, it requires a few extra steps. On my workbook I have two worksheets that the macro will be working between. Worksheet "Reps" has data in columns A:B with headers in Row 1 that need not be copied. The "Month" worksheet will be where the data is copying to. I would like the macro to copy cell B2 from the "Reps" worksheet into cell C4 on my "Month" worksheet and then copy cell A2 from the "Reps" worksheet into cell E4 on the "Month" worksheet. Once these are copied I would want range C7:J32 on the "Month" worksheet to Print to the default printer. This would then need to loop for however many rows contain data on the Macro sheet in columns A:B. Could you help out? Thanks!
 
Upvote 0
Hi Mark858,

Hoping you can help me to expand this to work for me because I'm at a loss. I'm trying to do something similar, however, it requires a few extra steps. On my workbook I have two worksheets that the macro will be working between. Worksheet "Reps" has data in columns A:B with headers in Row 1 that need not be copied. The "Month" worksheet will be where the data is copying to. I would like the macro to copy cell B2 from the "Reps" worksheet into cell C4 on my "Month" worksheet and then copy cell A2 from the "Reps" worksheet into cell E4 on the "Month" worksheet. Once these are copied I would want range C7:J32 on the "Month" worksheet to Print to the default printer. This would then need to loop for however many rows contain data on the Macro sheet in columns A:B. Could you help out? Thanks!

For the printing, I already have a macro established for that now that I think of it, so the new macro could simply run "Print_SnapShot" and then loop to the next row.
 
Upvote 0
Try the amendments below (untested so definitely test on a copy of your data).

Code:
Sub PrintLogs()
    Dim lastRow As Long, i As Long
    Dim ws As Worksheet
    Set ws = Sheets("Log")
    lastRow = ws.Range("A" & Rows.Count).End(xlUp).Row
    With ws
        For i = 2 To lastRow
            If Len(Trim(.Range("A" & i).Value)) <> 0 Then _
            .Range("J" & i).Formula = "Printed"
 .Range("A" & i).EntireRow.Copy
    Sheets("Print-Out").Range("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Sheets("Print-Out").PrintOut Copies:=1, Collate:=True, _
        IgnorePrintAreas:=False
        Next i
    End With
End Sub

Hello Mark858 or anyone else who may be able to help. I was wondering if this code can be modified in anyway to print out only cells that have print in them.
So modifying this code changing 'Printed' to 'Print' and it will run through the list following the same code but only print sheets with 'Print' in column J
 
Upvote 0

Forum statistics

Threads
1,206,755
Messages
6,074,754
Members
446,083
Latest member
kfunt

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