VBA Print help!!

Javi

Active Member
Joined
May 26, 2011
Messages
440
Hi All.
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p> </o:p>
I am new to VBA and I have been using the recorder to learn as well as this site however certain situations really stop me in my tracks. Your help would be greatly appreciated.
<o:p> </o:p>
I have a sheet with data in columns “A:G” I would like to put a button that would print the sheet down to the last row with data.
<o:p> </o:p>
The two things that are also needed
1. Print in Landscape
2. Use Row 2 and Row 3 as “Print titles” they need to print on all pages.
<o:p> </o:p>
THANKS!!
 

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.
Re: VBA Print help!! Got it!!

Got it!! the below code did the job!!

Thanks repairman615

Code:
Sub Print_Button()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
Dim ws As Worksheet, cell As Range<o:p></o:p>
Set ws = Sheets("main")<o:p></o:p>
Set cell = Range("g2000").End(xlUp)<o:p></o:p>
Do Until cell.Value <> ""<o:p></o:p>
Set cell = cell.Offset(-1, 0)<o:p></o:p>
Loop<o:p></o:p>
ws.PageSetup.PrintArea = ("A2:" & cell.Address)<o:p></o:p>
‘ws.PrintPreview
[COLOR=black][FONT=Courier]Application.Dialogs(xlDialogPrint).Show<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]End Sub[/FONT][/COLOR][COLOR=black][FONT=Courier]<o:p></o:p>[/FONT][/COLOR]
 
Upvote 0

Forum statistics

Threads
1,221,814
Messages
6,162,132
Members
451,743
Latest member
matt3388

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