ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   printing to a computed column (https://www.excelbanter.com/excel-programming/397937-printing-computed-column.html)

Dean[_8_]

printing to a computed column
 
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



Dave Peterson

printing to a computed column
 
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.


Dean wrote:

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


--

Dave Peterson

Dean[_8_]

printing to a computed column
 
Yup, that worked well. Thanks, Dave!
Dean

"Dave Peterson" wrote in message
...
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.


Dean wrote:

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


--

Dave Peterson





All times are GMT +1. The time now is 10:17 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com