ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How can I print from cell A1 to the last row ? (https://www.excelbanter.com/excel-programming/422244-how-can-i-print-cell-a1-last-row.html)

Ro477

How can I print from cell A1 to the last row ?
 
Thanks to all for their help so far. I can find the last row okay, but how
can I now print from cell A1 through to the last row +2, column 24 ?

Dim IngLastRow As Long
With Sheets("Report(metArb)")
lngLastRow = .Cells(Rows.Count, "B").End(xlUp).Row + 2
End With

.... that finds the last row, but to print from A1 to the lastrow+2 (which is
IngLastRow) is it

ActiveSheet.PageSetup.PrintArea = "$A$1:" & "IngLastRow+2,24"

thanks again ... Roger




Rick Rothstein

How can I print from cell A1 to the last row ?
 
There are a couple of problems with your statement. First, your IngLastRow
variable name is place inside quote marks, so VB will treat is as pure text
(anything inside quote marks is text with no meaning other than as a
collection of letters). To have VB evaluate the variable in order to
retrieve its contents, you must concatenate the variable to the fixed text.
Second, you start your range address with $A$1: and then try to finish it
off with a row-comma-column... you can't mix notations like that as VB will
have no idea what you are doing. This should be the line of code you are
looking for...

ActiveSheet.PageSetup.PrintArea = "$A$1:X" & (IngLastRow + 2)

--
Rick (MVP - Excel)


"Ro477" wrote in message
...
Thanks to all for their help so far. I can find the last row okay, but how
can I now print from cell A1 through to the last row +2, column 24 ?

Dim IngLastRow As Long
With Sheets("Report(metArb)")
lngLastRow = .Cells(Rows.Count, "B").End(xlUp).Row + 2
End With

... that finds the last row, but to print from A1 to the lastrow+2 (which
is IngLastRow) is it

ActiveSheet.PageSetup.PrintArea = "$A$1:" & "IngLastRow+2,24"

thanks again ... Roger





Bernard Liengme

How can I print from cell A1 to the last row ?
 
This works

Sub tryme()
With Sheets("sheet1")
lngLastRow = Cells(Rows.Count, "B").End(xlUp).Row + 2
myarea = "$A$1:$B" & lngLastRow
.PageSetup.PrintArea = myarea
End With
End Sub

Not sure what your 24 is about. Is it column a reference to column X?
If so use: myarea = "$A$1:$X" & lngLastRow
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"Ro477" wrote in message
...
Thanks to all for their help so far. I can find the last row okay, but how
can I now print from cell A1 through to the last row +2, column 24 ?

Dim IngLastRow As Long
With Sheets("Report(metArb)")
lngLastRow = .Cells(Rows.Count, "B").End(xlUp).Row + 2
End With

... that finds the last row, but to print from A1 to the lastrow+2 (which
is IngLastRow) is it

ActiveSheet.PageSetup.PrintArea = "$A$1:" & "IngLastRow+2,24"

thanks again ... Roger







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

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