ryanyoungsma
New Member
- Joined
- Feb 6, 2009
- Messages
- 2
Hi,
I have seen some posts regarding dynamic print ranges, but I have not been able to find quite what I need. So here it goes:
Problem Description:
I have an application where I allow a user to select from a list of "reports" on a form. Each report is on the same worksheet, so say 5 reports on the same worksheet. The reason for this is that for each worksheet we have 22 variations of the worksheet.
So once the user selects the reports(s) that they want we run a data retrieval method. To finalize the resulting workbook, I need to remove the reports that the user did not select from each worksheet. This is where things break.
What I have done:
- I have tried setting the print range on each worksheet in the main file, but once I delete the reports not needed, the print range disappears.
Here is the code for the sub that cleans up the worksheet as it is processed:
Other Information:
If anyone has any thoughts it would be appreciated. I am definitely stumped on this one.
Thank you,
Ryan
btw - My first post here so hopefully I have provided enough information.
I have seen some posts regarding dynamic print ranges, but I have not been able to find quite what I need. So here it goes:
Problem Description:
I have an application where I allow a user to select from a list of "reports" on a form. Each report is on the same worksheet, so say 5 reports on the same worksheet. The reason for this is that for each worksheet we have 22 variations of the worksheet.
So once the user selects the reports(s) that they want we run a data retrieval method. To finalize the resulting workbook, I need to remove the reports that the user did not select from each worksheet. This is where things break.
What I have done:
- I have tried setting the print range on each worksheet in the main file, but once I delete the reports not needed, the print range disappears.
Here is the code for the sub that cleans up the worksheet as it is processed:
Code:
Sub runReportCleanUp(ws As Worksheet)
'/------------------------------------------/'
' Delete reports not selected '
' OR Paste Special the data '
' @param: ws as Worksheet, Current WS Obj
'/------------------------------------------/'
Dim counter As Integer 'report counter
Dim printRange1 As String, printRange2 As String, printRange3 As String, printRange4 As String, printRange5 As String
Dim wsValue As String
'Update Status info
With UserForm1
.prgStatus = "(Cleaning up report page...)"
End With
DoEvents
'Activate the current worksheet
ws.Select
counter = 0
wsValue = ws.Range("A2").Value
'ws.PageSetup.PrintArea = Range(printRange1).Address & ", " & Range(printRange2).Address & ", " & _
Range(printRange3).Address & ", " & Range(printRange4).Address & ", " & _
Range(printRange5).Address
On Error Resume Next
'Paid Loss Development
If Not UserForm1.rpt_pld Then
Range(wsValue & "_PLD").Select 'Specific range on WS for specific report
selection.EntireColumn.Delete 'Deletes Columns from selection
ActiveWorkbook.names(wsValue & "_PLD").Delete 'Delete Named Range
Else
Range(wsValue & "_PLD").Select
selection.Copy
selection.PasteSpecial Paste:=xlValues
counter = counter + 1 'Increment counter
End If
'Part 1
If Not UserForm1.rpt_pt1 Then
Range(wsValue & "_PT1").Select
selection.EntireColumn.Delete 'Deletes Columns from selection
ActiveWorkbook.names(wsValue & "_PT1").Delete 'Delete Named Range
Else
Range(wsValue & "_PT1").Select
selection.Copy
selection.PasteSpecial Paste:=xlValues
counter = counter + 1 'Increment counter
End If
'Incurred Loss Development
If Not UserForm1.rpt_ild Then
Range(wsValue & "_ILD").Select
selection.EntireColumn.Delete
ActiveWorkbook.names(wsValue & "_ILD").Delete 'Delete Named Range
Else
Range(wsValue & "_ILD").Select
selection.Copy
selection.PasteSpecial Paste:=xlValues
counter = counter + 1 'Increment counter
End If
'Loss Reserves
If Not UserForm1.rpt_lrs Then
Range(wsValue & "_LRS").Select
selection.EntireColumn.Delete
ActiveWorkbook.names(wsValue & "_LRS").Delete 'Delete Named Range
Else
Range(wsValue & "_LRS").Select
selection.Copy
selection.PasteSpecial Paste:=xlValues
counter = counter + 1 'Increment counter
End If
'Parts 2- 6
If Not UserForm1.rpt_p26 Then
Range(wsValue & "_P26").Select
selection.EntireColumn.Delete
ActiveWorkbook.names(wsValue & "_P26").Delete 'Delete Named Range
Else
Range(wsValue & "_P26").Select
selection.Copy
selection.PasteSpecial Paste:=xlValues
counter = counter + 1 'Increment counter
End If
'Clean up selected range
Range("A1").Select
With ws.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
On Error GoTo 0
With ws.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.5)
.RightMargin = Application.InchesToPoints(0.5)
.TopMargin = Application.InchesToPoints(0.5)
.BottomMargin = Application.InchesToPoints(0.5)
.HeaderMargin = Application.InchesToPoints(0.5)
.FooterMargin = Application.InchesToPoints(0.5)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.CenterHorizontally = True
.CenterVertically = False
.Orientation = xlPortrait
.Draft = False
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = counter
.FitToPagesTall = 1
.PrintErrors = xlPrintErrorsDisplayed
End With
End Sub
Other Information:
- Each report has a defined name for it on each worksheet. This is what I use to delete the report.
- the worksheet object is passed to this sub from another process.
If anyone has any thoughts it would be appreciated. I am definitely stumped on this one.
Thank you,
Ryan
btw - My first post here so hopefully I have provided enough information.