ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   print out specified range in macro (https://www.excelbanter.com/excel-discussion-misc-queries/188785-print-out-specified-range-macro.html)

Wu

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

Mike H

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



All times are GMT +1. The time now is 11:41 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com