Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default using cells property

I am using excel 2003 and trying to print an area that will vary depending on
the number of players. Here is what I have now.


Dim players As Long
Dim pages As Long
Dim rowcount As Long


players = ActiveWorkbook.Sheets("week 1").Range("ad3").Value
pages = (players / 3)
rowcount = pages * 60

ActiveWorkbook.Sheets("individual stats").Range(Cells(2, 1), Cells(rowcount,
24)).PrintOut Copies:=1, Collate:=True

I am getting "application-defined or object-defined error" with the last
line highlighted. I checked the variable rowcount and it is correct. 900 in
this case.

When I substitute range("a2:x900") for range(cells(2,1),cells(rowcount,24)).
It work great, but it will not always be row 900. It wil vary.
Any help would be appreciated
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default using cells property

You would have found it would work if the active sheet. When you use Cells
you must specify the worksheet or excel thinks you are referring to the
active sheet.

You can either use
Sheets("individual stats").Range(Sheets("individual stats").Cells(2, 1), etc

or better to use With / End with like the following. Note the dot in front
of cells.

Note also that a space and underscore at the end of a line is a line break
in an otherwise single line of code.

With ActiveWorkbook.Sheets("individual stats")
.Range(.Cells(2, 1), _
.Cells(RowCount, 24)) _
.PrintOut Copies:=1, Collate:=True
End With

--
Regards,

OssieMac


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default using cells property

Thanks, that works. And I really appreciate you helping with why it works,
not just giving me some code to use. I am still in the learning phase and
you have really helped. Thanks a bunch

Jim

"OssieMac" wrote:

You would have found it would work if the active sheet. When you use Cells
you must specify the worksheet or excel thinks you are referring to the
active sheet.

You can either use
Sheets("individual stats").Range(Sheets("individual stats").Cells(2, 1), etc

or better to use With / End with like the following. Note the dot in front
of cells.

Note also that a space and underscore at the end of a line is a line break
in an otherwise single line of code.

With ActiveWorkbook.Sheets("individual stats")
.Range(.Cells(2, 1), _
.Cells(RowCount, 24)) _
.PrintOut Copies:=1, Collate:=True
End With

--
Regards,

OssieMac


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I use the .Cells property to refer to ActiveCell? Caeres Excel Discussion (Misc queries) 9 October 7th 08 02:56 PM
Merged cells Value2 property Sandrina Excel Programming 1 February 6th 06 02:58 PM
cells property Souris Excel Programming 1 August 18th 05 07:50 PM
How to use Cells property to Range object? deko[_2_] Excel Programming 4 March 8th 05 07:17 PM
Using Select with Range.Cells property Ralph Heidecke Excel Programming 2 January 15th 05 03:05 PM


All times are GMT +1. The time now is 02:26 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"