print out specified range in macro

W

Wu

I would like to write a macro to print out below information from
INVOICE NO. "2008-005" TO "2008-020"

I have write macro : firstinv = inputbox("input the first invoie")
lastinv= inputbox("input the last invoie")

now, how to wirte macro to use these information to print out the specified
range?

------------------------------------------------------------------------------------------------
INVOICE NO. ITEM QTY.
2008-001 PEN 100
2008-002 PAPER 1000
2008-005 RUBBER 200
2008-010 PEN 500
2008-011 PENCIL 10
2008-012 PAPER 200
2008-017 RULER 50
2008-020 PAPER 500
2008-021 PEN 60
 
M

Mike H

Hi,

This assumes you data are in columns A,B & C. Right click your sheet tab,
view code and paste this in. It's a bit messy but it works.

Sub setRange()
firstcell = InputBox("Enter first invoice nuumber", "Print Range")
lastcell = InputBox("Enter last invoice nuumber", "Print Range")
Dim myRange As Range
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Set myRange = Range("A1:A" & lastrow)

For Each c In myRange
If c.Value = firstcell Then first = c.Address
Next
If first = "" Then
MsgBox ("first invoice not found")
Exit Sub
End If

For Each c In myRange
If c.Value = lastcell Then last = c.Row
Next
If last = "" Then
MsgBox ("last invoice not found")
Exit Sub

End If
ActiveSheet.PageSetup.PrintArea = first & ":C" & last
ActiveSheet.PrintOut
End Sub

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top