VBA-Loop Help

hlpgilbert

New Member
Joined
Sep 25, 2011
Messages
3
Good Evening,

I have Created the below macro, however I cannot figure out how to make it loop so that is continues to copy the next column over ( so go from column E:E , To Column F:F, and then To Column G:G), and paste the data into the same column (D:D or Range paste_range) everytime, and print.
If anyone can help me it will be much appreciated.

Sub paster_print()
'
' paster_print Macro
'
'
Columns("E:E").Select
Selection.Copy
Application.Goto Reference:="paste_range"
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.Goto Reference:="Print_Area"
Application.CutCopyMode = False
End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
maybe like this
Code:
For i = 5 to 7
    Cells(1,i).EntireColumn.Copy
        Application.Goto Reference:="paste_range"
        Selection.PasteSpecial Paste:=xlPasteValues
        Application.Goto Reference:="Print_Area"
'add a print line if you want to print now, otherwise delete the line above this 'one
        Application.CutCopyMode = False
Next i
 
Upvote 0
You could have it print each column without the need to copy and paste. This prints each column one-at-a-time from columns E to J

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> Print_Each_Column()<br>    <br>    <SPAN style="color:#00007F">Dim</SPAN> col <SPAN style="color:#00007F">As</SPAN> Range<br>    <br>    <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> col <SPAN style="color:#00007F">In</SPAN> Range("E:J").Columns<br>        ActiveSheet.PageSetup.PrintArea = col.Address<br>        ActiveWindow.SelectedSheets.PrintOut Copies:=1<br>    <SPAN style="color:#00007F">Next</SPAN> col<br>    <br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0
Code:
ActiveWindow.SelectedSheets.PrintOut Copies:=1
I haven't done much printing via code, so I have a question... Why did you use the ActiveWIndows.SelectedSheets reference instead of just using an ActiveSheet reference? Your code using this statement in place of the one you posted appears to work the same way...

Code:
ActiveSheet.PrintOut Copies:=1
 
Upvote 0
I recorded the "print" function to get the syntax and didn't clean up the recorded code. ActiveWindow.SelectedSheets is what was recorded, but I would use ActiveSheet as well if I had taken the time to clean it up. I noticed it after I had posted.
 
Upvote 0
I recorded the "print" function to get the syntax and didn't clean up the recorded code. ActiveWindow.SelectedSheets is what was recorded, but I would use ActiveSheet as well if I had taken the time to clean it up. I noticed it after I had posted.
Thanks... I just wanted to make sure I wasn't missing something subtle here.
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,848
Members
452,948
Latest member
UsmanAli786

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