View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
NoodNutt[_2_] NoodNutt[_2_] is offline
external usenet poster
 
Posts: 39
Default Dynamic Sheet & Range Page Setup & Printing

Hi Team

Have been playing with this for the past hour or so and require your help please.

Now, I use the following to select a worksheet based on a fixed cell value:

If Not ws.Cells(myCell, "A").Value Is Nothing Then Sheets("" & myCell).Activate.

I am trying to incorporate this into my Dynamic Print Sheet selection, alas it does not work.

Essentially, the code looks @ If ws.Cells(i, "H").Value = "Y", if it does then go to that sheet.name and set it up for .PrintPreview/.Printing.

Dim ws As Worksheet
Dim i, ii, Count, lRow As Long
Dim myRng As Range

ii = 51
Set ws = Sheets("Fleet Summary")

For i = 5 To 50
If Not ws.Cells(i, "H").Value = "Y" Then Exit For

With ws
If Not .Cells(i, "A").Value Is Nothing Then
Sheets("" & i).Activate
End If
End With

With ActiveSheet
lRow = .Range("A" & .Rows.Count).End(xlUp).Row
Count = lRow
Set myRng = .Range("A1", "K" & Count)
If lRow < 70 Then
.ResetAllPageBreaks
.PageSetup.PrintArea = myRng.Address
While Count 0 And ii < lRow
If Count 51 Then
.HPageBreaks.Add befo=.Rows(ii)
End If
Wend
End If
.PageSetup.PaperSize = xlPaperA4
.PageSetup.Orientation = xlLandscape
.PageSetup.FitToPagesWide = 1
.PageSetup.FitToPagesTall = False
.PageSetup.LeftMargin = Application.CentimetersToPoints(28.347)
.PageSetup.RightMargin = Application.CentimetersToPoints(28.347)
.PageSetup.TopMargin = Application.CentimetersToPoints(28.347)
.PageSetup.BottomMargin = Application.CentimetersToPoints(28.347)
.PageSetup.HeaderMargin = Application.CentimetersToPoints(0)
.PageSetup.FooterMargin = Application.CentimetersToPoints(0)
.PageSetup.PrintTitleRows = "$1:$7"
.PageSetup.PrintTitleColumns = ""
.PageSetup.LeftHeader = ""
.PageSetup.CenterHeader = ""
.PageSetup.RightHeader = ""
.PageSetup.LeftFooter = ""
.PageSetup.CenterFooter = ""
.PageSetup.RightFooter = ""
.PageSetup.PrintHeadings = False
.PageSetup.CenterHorizontally = True
.PageSetup.CenterVertically = False
.PrintPreview
End With
Next i

TIA
Cheers
Mark.