Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 106
Default Set Print Area Macro

I have a routine that ultimately selects a range of cells that I want to use
for printing. After highlighting that block, how do I define that range so
that it is set as a print area. When I use record macro, even with relative
references, it seems to only record the, say, six column range that was
selected THIS time, such as F5:g10. Next time, with different data, the
macro will find a longer or shorter same six-column range and I need code
that knows that.

Thanks,
Grace


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Set Print Area Macro

Hi
try something like the following:
sub foo()
dim rng as range
with activesheet
set rng=selection
.PageSetup.PrintArea = rng.address
.printout
end with
end sub

--
Regards
Frank Kabel
Frankfurt, Germany


Grace wrote:
I have a routine that ultimately selects a range of cells that I want
to use for printing. After highlighting that block, how do I define
that range so that it is set as a print area. When I use record
macro, even with relative references, it seems to only record the,
say, six column range that was selected THIS time, such as F5:g10.
Next time, with different data, the macro will find a longer or
shorter same six-column range and I need code that knows that.

Thanks,
Grace


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 106
Default Set Print Area Macro

On my last post, I meant to use

F5:K10, not F5:g10. Sorry

Grace

"Grace" wrote in message
...
I have a routine that ultimately selects a range of cells that I want to

use
for printing. After highlighting that block, how do I define that range

so
that it is set as a print area. When I use record macro, even with

relative
references, it seems to only record the, say, six column range that was
selected THIS time, such as F5:g10. Next time, with different data, the
macro will find a longer or shorter same six-column range and I need code
that knows that.

Thanks,
Grace




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 106
Default Set Print Area Macro

Works nicely. Thanks Don, and Thomas.

Grace

"Don Guillett" wrote in message
...
example of how to find the last row in a column

x=cells(rows.count,"a").end(xlup).row
'to use in range
range("a1:g" & x)

--
Don Guillett
SalesAid Software

"Grace" wrote in message
...
I have a routine that ultimately selects a range of cells that I want to

use
for printing. After highlighting that block, how do I define that range

so
that it is set as a print area. When I use record macro, even with

relative
references, it seems to only record the, say, six column range that was
selected THIS time, such as F5:g10. Next time, with different data, the
macro will find a longer or shorter same six-column range and I need

code
that knows that.

Thanks,
Grace








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 106
Default Set Print Area Macro

When I added option explicit, as many suggest I do, it says x is undefined.
How should it be defined?

Thanks,

Grace

"Don Guillett" wrote in message
...
example of how to find the last row in a column

x=cells(rows.count,"a").end(xlup).row
'to use in range
range("a1:g" & x)

--
Don Guillett
SalesAid Software

"Grace" wrote in message
...
I have a routine that ultimately selects a range of cells that I want to

use
for printing. After highlighting that block, how do I define that range

so
that it is set as a print area. When I use record macro, even with

relative
references, it seems to only record the, say, six column range that was
selected THIS time, such as F5:g10. Next time, with different data, the
macro will find a longer or shorter same six-column range and I need

code
that knows that.

Thanks,
Grace






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Set Print Area Macro

Hi
you have to use
Dim x
for this. See the VBA help for 'Dim'

--
Regards
Frank Kabel
Frankfurt, Germany


Grace wrote:
When I added option explicit, as many suggest I do, it says x is
undefined. How should it be defined?

Thanks,

Grace

"Don Guillett" wrote in message
...
example of how to find the last row in a column

x=cells(rows.count,"a").end(xlup).row
'to use in range
range("a1:g" & x)

--
Don Guillett
SalesAid Software

"Grace" wrote in message
...
I have a routine that ultimately selects a range of cells that I
want to use for printing. After highlighting that block, how do I
define that range so that it is set as a print area. When I use
record macro, even with relative references, it seems to only
record the, say, six column range that was selected THIS time, such
as F5:g10. Next time, with different data, the macro will find a
longer or shorter same six-column range and I need code that knows
that.

Thanks,
Grace


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Set Print Area Macro

I'd use:

Dim x As Long

Long represents a whole number between -2,147,483,648 and 2,147,483,647.

And that's enough for any row number (1 to 65536).

You can look for "Data Type Summary" in VBA's help to see lots of different
types.

Grace wrote:

When I added option explicit, as many suggest I do, it says x is undefined.
How should it be defined?

Thanks,

Grace

"Don Guillett" wrote in message
...
example of how to find the last row in a column

x=cells(rows.count,"a").end(xlup).row
'to use in range
range("a1:g" & x)

--
Don Guillett
SalesAid Software

"Grace" wrote in message
...
I have a routine that ultimately selects a range of cells that I want to

use
for printing. After highlighting that block, how do I define that range

so
that it is set as a print area. When I use record macro, even with

relative
references, it seems to only record the, say, six column range that was
selected THIS time, such as F5:g10. Next time, with different data, the
macro will find a longer or shorter same six-column range and I need

code
that knows that.

Thanks,
Grace





--

Dave Peterson

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 106
Default Set Print Area Macro

Thanks Dave and Frank

"Dave Peterson" wrote in message
...
I'd use:

Dim x As Long

Long represents a whole number between -2,147,483,648 and 2,147,483,647.

And that's enough for any row number (1 to 65536).

You can look for "Data Type Summary" in VBA's help to see lots of

different
types.

Grace wrote:

When I added option explicit, as many suggest I do, it says x is

undefined.
How should it be defined?

Thanks,

Grace

"Don Guillett" wrote in message
...
example of how to find the last row in a column

x=cells(rows.count,"a").end(xlup).row
'to use in range
range("a1:g" & x)

--
Don Guillett
SalesAid Software

"Grace" wrote in message
...
I have a routine that ultimately selects a range of cells that I

want to
use
for printing. After highlighting that block, how do I define that

range
so
that it is set as a print area. When I use record macro, even with
relative
references, it seems to only record the, say, six column range that

was
selected THIS time, such as F5:g10. Next time, with different data,

the
macro will find a longer or shorter same six-column range and I need

code
that knows that.

Thanks,
Grace





--

Dave Peterson



  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default Set Print Area Macro

Grüezi Grace

Grace schrieb am 11.06.2004

I have a routine that ultimately selects a range of cells that I want to use
for printing. After highlighting that block, how do I define that range so
that it is set as a print area. When I use record macro, even with relative
references, it seems to only record the, say, six column range that was
selected THIS time, such as F5:g10. Next time, with different data, the
macro will find a longer or shorter same six-column range and I need code
that knows that.


Do you print in VBA?

Then you could use the following:

Selection.PrintOut

--
Regards

Thomas Ramel
- MVP for Microsoft-Excel -

[Win XP Pro SP-1 / xl2000 SP-3]


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
Defining a print area in a macro Steven Nairn Excel Discussion (Misc queries) 1 January 27th 10 10:35 PM
How do you set up a macro to reset the print area? Stuck2 Excel Discussion (Misc queries) 0 January 30th 06 03:50 PM
Pivot Table macro to set print area and print details of drill down data Steve Haskins Excel Discussion (Misc queries) 2 December 28th 05 04:59 PM
Create a print macro that would automatically select print area? wastedwings Excel Worksheet Functions 7 August 22nd 05 10:36 PM
Macro to select the print area Gavin[_3_] Excel Programming 5 July 29th 03 02:58 PM


All times are GMT +1. The time now is 09:34 AM.

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

About Us

"It's about Microsoft Excel"