Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
print out specified range in macro
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 |
#2
Posted to microsoft.public.excel.misc
|
|||
|
|||
print out specified range in macro
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 "Wu" wrote: 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Macro print range not dynamic like I wanted it to be | Excel Worksheet Functions | |||
Print Blank Pgs - Preview margins outside print range | Excel Discussion (Misc queries) | |||
Macro to print a selected range, not entire worksheet | Excel Discussion (Misc queries) | |||
Macro to set print range | New Users to Excel | |||
Print range macro | Excel Discussion (Misc queries) |