More help with setting multiple worksheets print area with VBA

K

KimberlyC

Hi
I'm running this code below (with the help of this group) to set the print
area in all worksheets (in my active workbook) that start with the name "cap
i details" (There can be many of these worksheets in a workbook with a #
after the name ....ex: cap i details (2) and so on).

This code sets the print area to the last entry in col A of the
worksheet...which made the worksheet print from A1:K?(last entry in col
A)... with A-K columns fitting on one worksheet across when printed.
This has been working fine...except now my worksheet/s has grown with more
columns.
I now have columns going over to "AG" -- they may all be used OR they may
not...

I still need to set my print area to the last entry in column A
but I also need to set the print area to the last coulmn used (with AG being
the last possible one to be used)

So..if the user uses columns A - L ( which they must use columns A-I), then
I want to set the print area to the last entry in col A and the last column
to included in the print area would be L
For Example:
If the last entry in col A is in A96, and the last coulmn used is L (cell
used is L92), then the print area would be A1:L96

Also....I have formulas in cells A8:AG8... the rest of the cells going down
are empty...unless the users fills them.


I'm not sure how to incorporate the above into the code below!!

Any help is greatly appreciated.

Thanks in advance!!


Public Sub PrintareaCAPIDetails()

Set sh1 = ActiveWorkbook.ActiveSheet
For Each Sh In ActiveWorkbook.Worksheets
If Left(LCase(Sh.Name), 13) = "cap i details" Then
Sh.Activate
ActiveWorkbook.ActiveSheet.PageSetup.PrintArea = "A1:K" & _
LastInCol(Sh.Range("A1"))
End If
Next
sh1.Activate

PrintForm.Show

End Sub
******************************************
Public Function LastInCol(rngInput As Range)
''Courtesy of http://www.j-walk.com, though a tad changed
Dim WorkRange As Range
Dim i As Integer, CellCount As Integer
Application.Volatile
Set WorkRange = rngInput.Columns(1).EntireColumn
Set WorkRange = Intersect(WorkRange.Parent.UsedRange, WorkRange)
CellCount = WorkRange.Count
For i = CellCount To 1 Step -1
If Not IsEmpty(WorkRange(i)) Then
LastInCol = WorkRange(i).Row
Exit Function
End If
Next i
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top