Print out data by selecting certain values

micpirie

New Member
Joined
Apr 2, 2014
Messages
6
Hi All.

I have a worksheet called Schedule. On this sheet I have an edited version of the year’s production, so the range could be from Row 1 to Row 3700.
In Column A I have the batch number with corresponding information along to Column G.
What I would like to do is to be able to print out the week’s production by having 2 dialog boxes, the first dialog box would ask for the first batch number, with the second one asking for the last batch number.
It would then print out all the information from the first batch number to the last, along with all the information held in Columns A to G.
Hopefully someone will be able to help me out, as it would make life so much simpler.
Kind regards
Mike
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Assuming there is a header on the first line.
VBA Code:
Sub test()
Dim Sn As Long, En As Long
Dim ans As String
Sn = Application.InputBox(Prompt:="Start", Type:=1)
If StrPtr(Sn) = 0 Then Exit Sub
En = Application.InputBox(Prompt:="End", Type:=1)
If StrPtr(En) = 0 Then Exit Sub
Range("A1").AutoFilter field:=1, Criteria1:=">=" & Sn, Operator:=xlAnd, Criteria2:="<=" & En
If WorksheetFunction.Subtotal(3, Range("A:A")) > 1 Then
        'Range(Range("A1"), Range("A1").SpecialCells(xlLastCell)).Value
        ActiveSheet.PageSetup.PrintTitleRows = Rows("1:1").Address
        ActiveSheet.PrintOut
End If
End Sub
 
Upvote 0
Assuming there is a header on the first line.
VBA Code:
Sub test()
Dim Sn As Long, En As Long
Dim ans As String
Sn = Application.InputBox(Prompt:="Start", Type:=1)
If StrPtr(Sn) = 0 Then Exit Sub
En = Application.InputBox(Prompt:="End", Type:=1)
If StrPtr(En) = 0 Then Exit Sub
Range("A1").AutoFilter field:=1, Criteria1:=">=" & Sn, Operator:=xlAnd, Criteria2:="<=" & En
If WorksheetFunction.Subtotal(3, Range("A:A")) > 1 Then
        'Range(Range("A1"), Range("A1").SpecialCells(xlLastCell)).Value
        ActiveSheet.PageSetup.PrintTitleRows = Rows("1:1").Address
        ActiveSheet.PrintOut
End If
End Sub
Thank you for your quick response. Unfortunately im still having a problem with the code. I should have probably said that the headings for the rows e.g. Batch number, destination etc are in columns A1 to G1. With the information starting in row 2. The code allows me to enter a start and end number but then only prints out the headings that are in in columns A to G.
Hopefully this will help
All the best
Mike
 
Upvote 0

Forum statistics

Threads
1,214,989
Messages
6,122,622
Members
449,093
Latest member
catterz66

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