Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
eagles1994
 
Posts: n/a
Default Set print range to a particular cell

I have a worksheet that when an existing macro is run on selected criteria
the data may contain a differing numbers of rows, eg data may finish at row
90 or row 100. The final row always contains the same data in column A.

How can I set the print area to be aligned with the final row?

Cheers
  #2   Report Post  
Smuggy
 
Posts: n/a
Default

Try using this Macro/routine by changing the word "Test" to whatever the
final row data in column A always is...

Sub PrintRange()
Dim c As Range
For Each c In Range(Range("A1"), Range("A65536").End(xlUp))
If c.Value = "Test" Then
Range("A1", c.Offset(0, 0).Address).Name = "Print_Area"
Exit For
End If
Next
End Sub



"eagles1994" wrote:

I have a worksheet that when an existing macro is run on selected criteria
the data may contain a differing numbers of rows, eg data may finish at row
90 or row 100. The final row always contains the same data in column A.

How can I set the print area to be aligned with the final row?

Cheers

  #3   Report Post  
Dave Peterson
 
Posts: n/a
Default

A non-macro approach:

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

(Make that 1000 big enough to extend past the last possible row.)

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

That last 3 represents the last column to print (A:C in my example).

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


eagles1994 wrote:

I have a worksheet that when an existing macro is run on selected criteria
the data may contain a differing numbers of rows, eg data may finish at row
90 or row 100. The final row always contains the same data in column A.

How can I set the print area to be aligned with the final row?

Cheers


--

Dave Peterson
  #4   Report Post  
Dave Peterson
 
Posts: n/a
Default

And if you need code, you could use something like:

Option Explicit
Sub testme01()
Dim LastRow As Long

With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
.PageSetup.PrintArea = "$A$1:$E" & LastRow
End With

End Sub

Change $E to the column that you want.

eagles1994 wrote:

I have a worksheet that when an existing macro is run on selected criteria
the data may contain a differing numbers of rows, eg data may finish at row
90 or row 100. The final row always contains the same data in column A.

How can I set the print area to be aligned with the final row?

Cheers


--

Dave Peterson
  #5   Report Post  
eagles1994
 
Posts: n/a
Default

Thanks for that guys. Works a treat!

Cheers
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
Function to determine if any cell in a range is contained in a given cell [email protected] Excel Worksheet Functions 3 February 7th 05 04:19 PM
Grabbing the last Non-empty cell in a range Arlen Excel Discussion (Misc queries) 2 January 22nd 05 05:15 PM
Searching text in a cell range ShareerIslamabadiMunda Excel Worksheet Functions 7 December 16th 04 09:55 PM
GET.CELL Biff Excel Worksheet Functions 2 November 24th 04 07:16 PM
Returning a Value to a Cell Based on a Range of Uncertain Size amc422 Excel Worksheet Functions 7 November 14th 04 03:03 PM


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