I know just enough VBA to be dangerous. I have a generalized spreadsheet with a summary report page. The data to be printed from the summary page varies. Therefore I'd like to build the PrintArea dynamically. As usual I've found several helpful hint on the web but can seem to tie it all together.
My plan was to use Chip Pearson's UNION2 function to test each potential print area (range) and combine them into one string. There are well over 60 different print areas / ranges on the summary sheet.
I think this should work if I can only figure out how to get the ranges to pass to the function properly. I've tried them as a string or ranges and an array of ranges. Of course, the key word is tried as I'm not really sure what I'm doing.
Here are samples of the ranges I want to test.
Payouts!$A4$d20 Payouts!$F4$i20 Payouts!$K4$n20
Payouts!$A21$d37 Payouts!$F21$i37 Payouts!$K21$n37
Payouts!$A38$d51 Payouts!$F38$i51 Payouts!$K38$n51
Payouts!$A52$d65 Payouts!$F52$i65 Payouts!$K52$n65
Payouts!$A66$d79 Payouts!$F66$i79 Payouts!$K66$n79
Payouts!$A80$d93 Payouts!$F80$i93 Payouts!$K80$n93
Payouts!$A94$d99 Payouts!$F94$i99 Payouts!$K94$n99
My plan was to use Chip Pearson's UNION2 function to test each potential print area (range) and combine them into one string. There are well over 60 different print areas / ranges on the summary sheet.
Code:
Function Union2(ParamArray Ranges() As Variant) As Range
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Union2 - Chip Pearson
' A Union operation that accepts parameters that are Nothing.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim N As Long
Dim RR As Range
For N = LBound(Ranges) To UBound(Ranges)
If IsObject(Ranges(N)) Then
If Not Ranges(N).cells(2,1) Is Nothing Then ' modified by user
If TypeOf Ranges(N) Is Excel.Range Then
If Not RR Is Nothing Then
Set RR = Application.Union(RR, Ranges(N))
Else
Set RR = Ranges(N)
End If
End If
End If
End If
Next N
Set Union2 = RR
End Function
I think this should work if I can only figure out how to get the ranges to pass to the function properly. I've tried them as a string or ranges and an array of ranges. Of course, the key word is tried as I'm not really sure what I'm doing.
Here are samples of the ranges I want to test.
Payouts!$A4$d20 Payouts!$F4$i20 Payouts!$K4$n20
Payouts!$A21$d37 Payouts!$F21$i37 Payouts!$K21$n37
Payouts!$A38$d51 Payouts!$F38$i51 Payouts!$K38$n51
Payouts!$A52$d65 Payouts!$F52$i65 Payouts!$K52$n65
Payouts!$A66$d79 Payouts!$F66$i79 Payouts!$K66$n79
Payouts!$A80$d93 Payouts!$F80$i93 Payouts!$K80$n93
Payouts!$A94$d99 Payouts!$F94$i99 Payouts!$K94$n99