LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Exract individual page ranges from sheet

Give the following function a try (it will only work in XL2007); just pass
in the page number whose address you want to find and optionally specify the
worksheet name (the function will default to the ActiveSheet if nothing is
passed into this argument).

Public Function PageAddress(PageNumber As Long, _
Optional SheetName As String) As String
Dim WS As Worksheet
Dim X As Long
Dim TopRow As Long, BottomRow As Long
Dim LeftCol As Long, RightCol As Long
Dim LastUsedRow As Long, LastUsedCol As Long
Dim LeftEdgeIndex As Long, TopEdgeIndex As Long
Dim TopEdges() As Long, LeftEdges() As Long
If Len(SheetName) = 0 Then
Set WS = ActiveSheet
Else
Set WS = Worksheets(SheetName)
End If
If PageNumber WS.PageSetup.Pages.Count Then
PageAddress = "No Such Page Number!"
Exit Function
End If
On Error GoTo EmptySheet
LastUsedRow = WS.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious).Row
LastUsedCol = WS.Cells.Find(What:="*", SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
On Error GoTo PageNumberError
ReDim TopEdges(1 To WS.VPageBreaks.Count + 2)
ReDim LeftEdges(1 To WS.HPageBreaks.Count + 2)
TopEdges(1) = 1
LeftEdges(1) = 1
TopEdges(UBound(TopEdges)) = LastUsedCol + 1
LeftEdges(UBound(LeftEdges)) = LastUsedRow + 1
For X = 1 To WS.HPageBreaks.Count
LeftEdges(X + 1) = WS.HPageBreaks(X).Location.Row
Next
For X = 1 To WS.VPageBreaks.Count
TopEdges(X + 1) = WS.VPageBreaks(X).Location.Column
Next
TopEdgeIndex = 1 + ((PageNumber - 1) \ (WS.HPageBreaks.Count + 1))
LeftEdgeIndex = 1 + ((PageNumber - 1) Mod (WS.HPageBreaks.Count + 1))
PageAddress = Cells(LeftEdges(LeftEdgeIndex), TopEdges(TopEdgeIndex)). _
Address & ":" & Cells(LeftEdges(LeftEdgeIndex + 1), _
TopEdges(TopEdgeIndex + 1)).Offset(-1, -1).Address
Exit Function
EmptySheet:
PageAddress = "No Data On Sheet!"
Exit Function
PageNumberError:
PageAddress = "Page Numbering Error!"
End Function

--
Rick (MVP - Excel)


"xp" wrote in message
...
Using Excel 2007 and Win XP;

I have several pages delineated by page breaks all residing in one sheet.
I
am trying to obtain the cell address of, say, page 3. I figure this would
be
the range address of the top left cell and bottom right cell in the range
of
page 3 (which can most easily be seen in PageBreakPreview).

I tried using PrintArea, but that gives me the print range of the entire
sheet, I just need one page (I need to be able to get any individual
page).
Can anyone please post some code that will enable me to do this?

Thanks much in advance.


 
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
How can Enter Page Numbers and/or page ranges separated by commas. d Excel Discussion (Misc queries) 1 December 3rd 08 03:41 PM
more than 2 secondary y axis with individual ranges of value Big G Charts and Charting in Excel 4 May 22nd 07 01:59 PM
How do I save an individual page in a workbook? Sharon Williams Excel Worksheet Functions 2 December 14th 06 02:14 PM
Individual Page Selection Chris Shaw[_3_] Excel Programming 1 July 11th 05 08:12 PM
Return an array of all page ranges in a sheet? slovical Excel Programming 1 February 4th 04 09:07 PM


All times are GMT +1. The time now is 05:02 AM.

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"