Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Wu Wu is offline
external usenet poster
 
Posts: 36
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro print range not dynamic like I wanted it to be TRYING Excel Worksheet Functions 8 November 27th 07 01:05 AM
Print Blank Pgs - Preview margins outside print range dsm Excel Discussion (Misc queries) 0 October 25th 06 06:17 PM
Macro to print a selected range, not entire worksheet James C Excel Discussion (Misc queries) 3 October 19th 05 10:12 PM
Macro to set print range Brisbane Rob New Users to Excel 2 September 4th 05 03:50 AM
Print range macro nc Excel Discussion (Misc queries) 3 March 21st 05 04:38 PM


All times are GMT +1. The time now is 07:55 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"