Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Application-defined or object-defined error - missing the basics

I am confident that the following problem stems from my lack of
understanding the core basics of VB.

The following code works even when the sheet "CostAttributes" is not
selected.

Dim cellcount As Long
Sheets("CostAttributes").Select
cellcount = Sheets("CostAttributes").Range(("A7"),
Range("A7").End(xlDown)).Rows.Count

However I am trying to avoid having to select the "CostAttributes"
sheet in the code so I have written:

Dim cellcount As Long
cellcount = Sheets("CostAttributes").Range(("A7"),
Range("A7").End(xlDown)).Rows.Count

and I get the application-defined or object-defined error message.
Can anyone please help a lost newbie with this?

TIA,

Brent

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Application-defined or object-defined error - missing the basics

Brent,

You need to fully qualify your range object, otherwise, any range object
defaults to the active sheet. Simply change

cellcount = Sheets("CostAttributes").Range(("A7"), _
Range("A7").End(xlDown)).Rows.Count

to

With Sheets("CostAttributes")
cellcount = .Range(.Range("A7"), .Range("A7").End(xlDown)).Rows.Count
End With

which is the same as:

cellcount =
Sheets("CostAttributes").Range(Sheets("CostAttribu tes").Range("A7"),
Sheets("CostAttributes").Range("A7").End(xlDown)). Rows.Count

HTH,
Bernie
MS Excel MVP

wrote in message
oups.com...
I am confident that the following problem stems from my lack of
understanding the core basics of VB.

The following code works even when the sheet "CostAttributes" is not
selected.

Dim cellcount As Long
Sheets("CostAttributes").Select
cellcount = Sheets("CostAttributes").Range(("A7"),
Range("A7").End(xlDown)).Rows.Count

However I am trying to avoid having to select the "CostAttributes"
sheet in the code so I have written:

Dim cellcount As Long
cellcount = Sheets("CostAttributes").Range(("A7"),
Range("A7").End(xlDown)).Rows.Count

and I get the application-defined or object-defined error message.
Can anyone please help a lost newbie with this?

TIA,

Brent



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
Run-time error '50290': Application-defined or object-defined erro Macro button Excel Discussion (Misc queries) 1 March 12th 09 10:59 AM
Macro Run-time Error 1004 Application Defined or Object Defined Error Anddmx Excel Programming 6 June 9th 04 03:40 PM
Application-defined or object-defined error Sharon[_5_] Excel Programming 2 October 24th 03 03:49 PM
Runtime Error 1004 -- Application Defined or Object Defined Error John[_51_] Excel Programming 3 September 4th 03 04:28 PM


All times are GMT +1. The time now is 12:15 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"