Range is not being picked up

S

Sheeny

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!
 
D

Dave Peterson

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
 

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