printing to a computed column

D

Dean

I have the following macro below that prints out from column A thru DS (at
least it does without the first two lines of code (using "lastcolumn") that
I just added because I want you to help me integrate them into the macro).
It works fine, but in most cases, many of the rightmost columns to the right
are all zeroes, etc. In that case, I want to use a parameter to tell it to
only print the first so many leftmost columns.

Sub PrintTotalCFCityView()


Dim lastcolumn
lastcolumn = Max(Sheets("totalCF").Range("C405"),
Sheets("totalCF").Range("C408"),119).



Sheets("TotalCF").Select
Range("A1:DS431").Select
Selection.Printout Copies:=1, Collate:=True
Application.Goto Reference:="R1C1"
Range("A3").Select

End Sub

Columns A thru C always get printed and, beginning in column D, in the first
row, is a counter that counts the number of months from left to right. So,
cell D1 shows 0 (for month zero) and Cell E1 shows 1, cell F1 shows 2 ...
column DS shows 119.

Hoping that my syntax is correct for the "lastcolumn" variable above, I'd
like to use that variable (which should produce a number like, say, 44) to
replace the DS column in the macro.

So, if "lastcolumn" were equal to 1, for example, I would want to print only
columns A thru E, if 2, columns A thru F, if 119, then I would want to
print all the way to column DS.

Can someone add to/rewrite the macro above, so the DS341 is changed to row
341 of a column that varies as just described, using the "lastcolumn"
dimensioned variable? Thank you very much.

Dean
 
D

Dave Peterson

Maybe...


Option Explicit
Sub PrintTotalCFCityView()
Dim lastcolumn As Long

With Worksheets("totalcf")
lastcolumn = Application.Max(.Range("C405").Value, _
.Range("C408").value, _
119)
.Range("A1", .Cells(431, lastcolumn + 4)).PrintOut _
Copies:=1, Collate:=True
End With

End Sub

Untested, uncompiled.
 
D

Dean

Yup, that worked well. Thanks, Dave!
Dean

Dave Peterson said:
Maybe...


Option Explicit
Sub PrintTotalCFCityView()
Dim lastcolumn As Long

With Worksheets("totalcf")
lastcolumn = Application.Max(.Range("C405").Value, _
.Range("C408").value, _
119)
.Range("A1", .Cells(431, lastcolumn + 4)).PrintOut _
Copies:=1, Collate:=True
End With

End Sub

Untested, uncompiled.
 

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