Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Using names ranges to set print area in a macro

Hi all,

Hope somebody can help me out!

I would like to run a macro to set a print area.

I need to print columns A thru S only.
I need to define the bottom row of the print area to be the last row
before column A becomes blank.

(The length of the list of data is dynamic, therefore I cannot use a
static range. I wish to omit any row below the point when column A
becomes blank, and I am unable to sort the data in anyway.)

I was thinking of using an IF statement inside a named range.

Any ideas?

Thanks in advance.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 989
Default Using names ranges to set print area in a macro

This is one way to name your print range:

Sub test()

Range("a1").Offset(Cells.SpecialCells(xlCellTypeLa stCell).Row + 1,
0).End(xlUp).Select
Range(Cells(1, 1), Cells(ActiveCell.Row, Range("s1").Column)).Name =
"rgPrint"

End Sub


"Dave Compton" wrote:

Hi all,

Hope somebody can help me out!

I would like to run a macro to set a print area.

I need to print columns A thru S only.
I need to define the bottom row of the print area to be the last row
before column A becomes blank.

(The length of the list of data is dynamic, therefore I cannot use a
static range. I wish to omit any row below the point when column A
becomes blank, and I am unable to sort the data in anyway.)

I was thinking of using an IF statement inside a named range.

Any ideas?

Thanks in advance.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Using names ranges to set print area in a macro

Insert Name =Define

for Sheet1!Print_Area use

=Offset(Sheet1!$A$1,0,0,CountA(Sheet1!$A:$A),19)


If you go into page setup, the formula can be destroyed.

--
Regards,
Tom Ogilvy


"Dave Compton" wrote in message
ups.com...
Hi all,

Hope somebody can help me out!

I would like to run a macro to set a print area.

I need to print columns A thru S only.
I need to define the bottom row of the print area to be the last row
before column A becomes blank.

(The length of the list of data is dynamic, therefore I cannot use a
static range. I wish to omit any row below the point when column A
becomes blank, and I am unable to sort the data in anyway.)

I was thinking of using an IF statement inside a named range.

Any ideas?

Thanks in advance.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 989
Default Using names ranges to set print area in a macro

=Offset(Sheet1!$A$1,0,0,CountA(Sheet1!$A:$A),19)

Am I right that requires column A to have no holes in the data? ... to be a
required field?

(Perhaps that is the case)

But, if there were an entry in A1, A2, and A4, it would still report 3, is
what I mean.

Right?
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Using names ranges to set print area in a macro

Yep.

But you can work around it:

Insert|Name|Define
Names in workbook: Sheet1!LastRow
Use this formula
Refers to: =LOOKUP(2,1/(Sheet1!$A$1:$A$2000<""),ROW(Sheet1!$A$1:$A$2000) )

(Make that 2000 big enough to extend past the last possible row--but don't use
the whole column.)

Then once mo
Insert|Name|Define
Names in workbook: Sheet1!Print_Area
Use this formula
Refers to: =OFFSET(Sheet1!$A$1,0,0,lastRow,5)

That last 5 represents the last column to print (A:E).

And change the worksheet (sheet1) if necessary (in all the places).

mark wrote:

=Offset(Sheet1!$A$1,0,0,CountA(Sheet1!$A:$A),19)


Am I right that requires column A to have no holes in the data? ... to be a
required field?

(Perhaps that is the case)

But, if there were an entry in A1, A2, and A4, it would still report 3, is
what I mean.

Right?


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Using names ranges to set print area in a macro

Wow! I tried all of them and they all worked! Now I have to choose
one.......tough call.

Thanks for the replies guys. Really appreciated. This helped complete
an important project which should help secure my promotion!

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
Print area composed by more ranges Andrea Excel Discussion (Misc queries) 2 February 21st 07 07:25 PM
Print Area ranges print on separate pages? Lyndon Excel Discussion (Misc queries) 1 December 29th 06 05:22 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
Set Print Area with a macro June Excel Programming 4 July 19th 04 07:40 PM


All times are GMT +1. The time now is 11:26 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"