Hi,
I need some help creating macro to print ranges of columns dynamically. Below is my code ..
Sub PrintInFormat()
Dim i As Integer
Dim colReport, currentCol, colIncrement
colReport = 4
colIncrement = 6
currentCol = colReport
Do While Cells(28, currentCol).Value <> ""
ActiveSheet.PageSetup.PrintArea = ""
ActiveSheet.PageSetup.PrintArea = _
Range(Cells(25, 1), Cells(62, currentCol + colIncrement - 1)).Address
With ActiveSheet.PageSetup
.LeftMargin = Application.InchesToPoints(0.25)
.RightMargin = Application.InchesToPoints(0.25)
.TopMargin = Application.InchesToPoints(0.25)
.BottomMargin = Application.InchesToPoints(0.25)
.HeaderMargin = Application.InchesToPoints(0.25)
.FooterMargin = Application.InchesToPoints(0.25)
.Orientation = xlLandscape
.PaperSize = xlPaperLetter
.FitToPagesWide = 1
.FitToPagesTall = 1
.Zoom = 60
End With
ActiveSheet.PrintOut
For i = 1 To colIncrement
ActiveSheet.Columns(currentCol).Hidden = True
currentCol = currentCol + 1
Next i
colIncrement = 18
Loop
----------------------
So, basically, i want to select print area dynamically (columns changing) and then print it. So here, i want to print column 1 to 9 in the 1st pass which is printing correctly. Then, i want to hide column 4 to 9 and then print column 1 to 3 and then 10 to 27 ( 3 main columns and 18 other columns). Now here, it does print that way but at the same time, it is also printing first 3 columns in another page as well. Then I am hiding last 18 columns and then print another sets (first 3 columns and another 18 columns) and so on..
So, eventhough i am resetting my print area in starting of each loop, it looks like it is not clearning them. Also, i am getting correct range for my printing in ActiveSheet.PageSetup.PrintArea = _
Range(.....) but it is still not printing correctly with ActiveSheet.PrintOut
Thanks in advance..
Quick response will highly be appreciated ..
Sam.
I need some help creating macro to print ranges of columns dynamically. Below is my code ..
Sub PrintInFormat()
Dim i As Integer
Dim colReport, currentCol, colIncrement
colReport = 4
colIncrement = 6
currentCol = colReport
Do While Cells(28, currentCol).Value <> ""
ActiveSheet.PageSetup.PrintArea = ""
ActiveSheet.PageSetup.PrintArea = _
Range(Cells(25, 1), Cells(62, currentCol + colIncrement - 1)).Address
With ActiveSheet.PageSetup
.LeftMargin = Application.InchesToPoints(0.25)
.RightMargin = Application.InchesToPoints(0.25)
.TopMargin = Application.InchesToPoints(0.25)
.BottomMargin = Application.InchesToPoints(0.25)
.HeaderMargin = Application.InchesToPoints(0.25)
.FooterMargin = Application.InchesToPoints(0.25)
.Orientation = xlLandscape
.PaperSize = xlPaperLetter
.FitToPagesWide = 1
.FitToPagesTall = 1
.Zoom = 60
End With
ActiveSheet.PrintOut
For i = 1 To colIncrement
ActiveSheet.Columns(currentCol).Hidden = True
currentCol = currentCol + 1
Next i
colIncrement = 18
Loop
----------------------
So, basically, i want to select print area dynamically (columns changing) and then print it. So here, i want to print column 1 to 9 in the 1st pass which is printing correctly. Then, i want to hide column 4 to 9 and then print column 1 to 3 and then 10 to 27 ( 3 main columns and 18 other columns). Now here, it does print that way but at the same time, it is also printing first 3 columns in another page as well. Then I am hiding last 18 columns and then print another sets (first 3 columns and another 18 columns) and so on..
So, eventhough i am resetting my print area in starting of each loop, it looks like it is not clearning them. Also, i am getting correct range for my printing in ActiveSheet.PageSetup.PrintArea = _
Range(.....) but it is still not printing correctly with ActiveSheet.PrintOut
Thanks in advance..
Quick response will highly be appreciated ..
Sam.