VBA to have Input Box Determine Number of Rows to Include in Print Area with Offset and Header

lamarh755

New Member
Joined
Jan 28, 2020
Messages
38
Office Version
  1. 2013
I have a spreadsheet that I am trying to have an input box applied to vba coding that will enable me to enter a value in the input box that will determine the number of rows to print. Here are the specifics.

The Header starts at row 7 and goes from column A through column H.
The data starts at row 8.
When I enter 100 in the input box, I would like for the print area to capture the header from A7 to H7 and continue down 100 lines.

The current code that I have works but it starts counting the rows from row 1, so I only end up getting 93 lines of data when i enter 100 instead of the header plus 100 rows. Any assistance would be greatly appreciated.


.
Macro 2025-01-11 143602.png
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
I'm sure there are many solutions to this

But here is a simple one

Code:
With Ws
.PageSetup.PrintArea = .Range("A7:H" & numRows + 7).Address
End With
 
Upvote 0
Solution
I'm sure there are many solutions to this

But here is a simple one

Code:
With Ws
.PageSetup.PrintArea = .Range("A7:H" & numRows + 7).Address
End With
I'm sure there are many solutions to this

But here is a simple one

Code:
With Ws
.PageSetup.PrintArea = .Range("A7:H" & numRows + 7).Address
End With
I'm not sure what happened above but here is another idea if you want to ditch the InputBox altogether.

Code:
Dim Wb As ThisWorkbook
Dim Ws As Worksheet

Set Ws = Wb.Sheets("YourSheetName")

Lr = Ws.Cells(Rows.Count, 1).End(xlUp).Row

With Ws
   .PageSetup.PrintArea = .Range("A7:H" & Lr).Address
End With
 
Upvote 0
I'm not sure what happened above but here is another idea if you want to ditch the InputBox altogether.

Code:
Dim Wb As ThisWorkbook
Dim Ws As Worksheet

Set Ws = Wb.Sheets("YourSheetName")

Lr = Ws.Cells(Rows.Count, 1).End(xlUp).Row

With Ws
   .PageSetup.PrintArea = .Range("A7:H" & Lr).Address
End With
Thank you. I need the input box because I don't want to capture all of the lines in the spreadsheet, just a certain number that will change based on the amount of counts I think my team can complete each day. Thank you for providing both!
 
Upvote 0

Forum statistics

Threads
1,225,626
Messages
6,186,095
Members
453,337
Latest member
fiaz ahmad

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