ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Range is not being picked up (https://www.excelbanter.com/excel-programming/360599-range-not-being-picked-up.html)

Sheeny[_26_]

Range is not being picked up
 

Please take a look at my code, I am trying to pick up the range and
print it, depending on the analysis years.

Dim area As String
Dim startrow(1) As Integer
Dim startcol(1) As Integer
Dim endrow(1) As Integer
Dim endcol(1) As Integer
Dim vern_startrow(1) As Integer
Dim vern_startcol(1) As Integer
Dim vern_endrow(1) As Integer
Dim vern_endcol(1) As Integer

fstyr = Range("FirstAll")
lstyr = Range("LastAll")

Sheets("Personal P_L").Select
For i = 1 To 15
startrow(1) = 1
startcol(1) = 20 'T
endrow(1) = 56 + 2 * (lstyr - fstyr)
endcol(1) = 46 'AT
With ActiveSheet.PageSetup
..Orientation = xlLandscape
..PaperSize = xlPaperLegal
..Range(.Cells(startrow, startcol), .Cells(endrow,
endcol)).Select
End With
Selection.PrintOut Copies:=1, Collate:=True
Next i

It gives me an error regarding my Range function...any help???

Thanks!


--
Sheeny
------------------------------------------------------------------------
Sheeny's Profile: http://www.excelforum.com/member.php...fo&userid=9082
View this thread: http://www.excelforum.com/showthread...hreadid=538967


Dave Peterson

Range is not being picked up
 
Are you writing about this line:

..Range(.Cells(startrow, startcol), .Cells(endrow, endcol)).Select

(assuming that the leading dot got eaten by the posting)

..range and both .cells() reference don't belong to the activesheet.pagesetup
property. They belong to something that can hold a range--like a worksheet.

And I'm not sure why you tried to use arrays for your variables. And as a rule,
I never use Integer. Integers can only go to +/- 32k (about). But you can have
rows up to 65536 (64k).

And you don't need to select stuff (worksheets or ranges) to work with them.

I'm not sure if this does what you intended, but it did compile for me:

Option Explicit
Sub testme()

Dim StartRow As Long
Dim StartCol As Long
Dim EndRow As Long
Dim EndCol As Long
Dim i As Long

Dim FstYr As Double
Dim LstYr As Double

With Worksheets("Personal P_L")
FstYr = .Range("FirstAll").Value
LstYr = .Range("LastAll").Value

'these don't change, so don't put them in the loop.
With .PageSetup
.Orientation = xlLandscape
.PaperSize = xlPaperLegal
End With

StartRow = 1
StartCol = 20 'T
EndCol = 46 'AT
EndRow = 56 + 2 * (LstYr - FstYr)

'why not just print once and make copies:=15????
For i = 1 To 15
.Range(.Cells(StartRow, StartCol), _
.Cells(EndRow, EndCol)).PrintOut Copies:=1, Collate:=True
Next i

End With
End Sub


Sheeny wrote:

Please take a look at my code, I am trying to pick up the range and
print it, depending on the analysis years.

Dim area As String
Dim startrow(1) As Integer
Dim startcol(1) As Integer
Dim endrow(1) As Integer
Dim endcol(1) As Integer
Dim vern_startrow(1) As Integer
Dim vern_startcol(1) As Integer
Dim vern_endrow(1) As Integer
Dim vern_endcol(1) As Integer

fstyr = Range("FirstAll")
lstyr = Range("LastAll")

Sheets("Personal P_L").Select
For i = 1 To 15
startrow(1) = 1
startcol(1) = 20 'T
endrow(1) = 56 + 2 * (lstyr - fstyr)
endcol(1) = 46 'AT
With ActiveSheet.PageSetup
Orientation = xlLandscape
PaperSize = xlPaperLegal
Range(.Cells(startrow, startcol), .Cells(endrow,
endcol)).Select
End With
Selection.PrintOut Copies:=1, Collate:=True
Next i

It gives me an error regarding my Range function...any help???

Thanks!

--
Sheeny
------------------------------------------------------------------------
Sheeny's Profile: http://www.excelforum.com/member.php...fo&userid=9082
View this thread: http://www.excelforum.com/showthread...hreadid=538967


--

Dave Peterson


All times are GMT +1. The time now is 07:17 PM.

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