![]() |
Print range & Command Button
I have one sheet named Data and another sheet that contains two command
buttons. I want to press Command Button1 and have a print out of range A1:G20 from the Data sheet. When I press Command Button2 I want a print out of range A25:L35 from the Data sheet. I recorded a macro from the sheet where my print buttons are to see the code. It is as follows: Sub Macro1() Sheets("Data").Select Range("A1:G20").Select Selection.PrintOut Copies:=1, Collate:=True Sheets("Print Buttons").Select End Sub I then created the command buttons and applied that code with the respective ranges for each button, but it created an error. When I press my print command buttons, I get a print out of a blank page, not the data in the respective ranges. What am I doing wrong? Thanks for any help. |
Print range & Command Button
Tim,
Try using this instead: Sub Macro1 Worksheets("Data").Range("A1:G20").PrintOut Copies:=1, Collate:=True end sub I got this to work. WhippyUSA TimN wrote: I have one sheet named Data and another sheet that contains two command buttons. I want to press Command Button1 and have a print out of range A1:G20 from the Data sheet. When I press Command Button2 I want a print out of range A25:L35 from the Data sheet. I recorded a macro from the sheet where my print buttons are to see the code. It is as follows: Sub Macro1() Sheets("Data").Select Range("A1:G20").Select Selection.PrintOut Copies:=1, Collate:=True Sheets("Print Buttons").Select End Sub I then created the command buttons and applied that code with the respective ranges for each button, but it created an error. When I press my print command buttons, I get a print out of a blank page, not the data in the respective ranges. What am I doing wrong? Thanks for any help. |
Print range & Command Button
you could try something like this:
Sub test() Dim ws As Worksheet Dim rng As Range Set ws = Worksheets("data") Set rng = ws.Range("A1:G20") With ws.PageSetup .HeaderMargin = Application.InchesToPoints(0.25) .LeftHeader = "" .RightMargin = Application.InchesToPoints(0.4) .LeftMargin = Application.InchesToPoints(0.4) .TopMargin = Application.InchesToPoints(1.5) .BottomMargin = Application.InchesToPoints(0.5) .PrintArea = rng.Address .CenterHeader = "" .CenterHorizontally = True .CenterVertically = False .Zoom = 100 End With With ws .PrintPreview .PrintOut Copies:=1, Collate:=True End With End Sub -- Gary "TimN" wrote in message ... I have one sheet named Data and another sheet that contains two command buttons. I want to press Command Button1 and have a print out of range A1:G20 from the Data sheet. When I press Command Button2 I want a print out of range A25:L35 from the Data sheet. I recorded a macro from the sheet where my print buttons are to see the code. It is as follows: Sub Macro1() Sheets("Data").Select Range("A1:G20").Select Selection.PrintOut Copies:=1, Collate:=True Sheets("Print Buttons").Select End Sub I then created the command buttons and applied that code with the respective ranges for each button, but it created an error. When I press my print command buttons, I get a print out of a blank page, not the data in the respective ranges. What am I doing wrong? Thanks for any help. |
Print range & Command Button
TimN, I used your code and it worked on my system. The only thing I changed
was instead of sheets("data") I used Sheets(1). "TimN" wrote: I have one sheet named Data and another sheet that contains two command buttons. I want to press Command Button1 and have a print out of range A1:G20 from the Data sheet. When I press Command Button2 I want a print out of range A25:L35 from the Data sheet. I recorded a macro from the sheet where my print buttons are to see the code. It is as follows: Sub Macro1() Sheets("Data").Select Range("A1:G20").Select Selection.PrintOut Copies:=1, Collate:=True Sheets("Print Buttons").Select End Sub I then created the command buttons and applied that code with the respective ranges for each button, but it created an error. When I press my print command buttons, I get a print out of a blank page, not the data in the respective ranges. What am I doing wrong? Thanks for any help. |
All times are GMT +1. The time now is 12:07 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com