Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 1004 App - defined or object-defined error

When I run a procedure with this line of code I get the 1004 app
define... error. Yet when I place the cursor over the variables it
references the right worksheet, column, and row. and even the value.
What's wrong with this line of code if:

Debug.Print Worksheets(glr_CopyWKS).Range(Cells(lngHeader,
lngX)).Value

glr_copywks = the activeworksheet
lngheader = a row in the activeworksheet
and lngx = a column in the activeworksheet

TIA

Stan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default 1004 App - defined or object-defined error

Two problems:

The first bites every coder at least once, and usually multiple
times...

Cells(), when unqualified, defaults to the ActiveSheet, so your
statment is equivalent to

Debug.Print Worksheets(glr_CopyWKS).Range(ActiveSheet.Cells( _
lngHeader, lngX)).Value

So if glr_CopyWKS is not the activesheet, the Range fails since
ranges can only be child objects of one sheet.

The second the Range(Cells(...)) construct. Look at VBA Help (Range
Property) - the syntax for Range() requires either a single A1 cell
reference (syntax 1) or two A1-style cell references or range
objects (syntax 2). In this case, using Range() is redundant. Try:

Debug.Print Worksheets(glr_CopyWKS).Cells(lngHeader, lngX).Value



In article ,
(Stan Plumber) wrote:

When I run a procedure with this line of code I get the 1004 app
define... error. Yet when I place the cursor over the variables it
references the right worksheet, column, and row. and even the value.
What's wrong with this line of code if:

Debug.Print Worksheets(glr_CopyWKS).Range(Cells(lngHeader,
lngX)).Value

glr_copywks = the activeworksheet
lngheader = a row in the activeworksheet
and lngx = a column in the activeworksheet

TIA

Stan

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 1004 App - defined or object-defined error

Thanks. Worked great.



"J.E. McGimpsey" wrote in message ...
Two problems:

The first bites every coder at least once, and usually multiple
times...

Cells(), when unqualified, defaults to the ActiveSheet, so your
statment is equivalent to

Debug.Print Worksheets(glr_CopyWKS).Range(ActiveSheet.Cells( _
lngHeader, lngX)).Value

So if glr_CopyWKS is not the activesheet, the Range fails since
ranges can only be child objects of one sheet.

The second the Range(Cells(...)) construct. Look at VBA Help (Range
Property) - the syntax for Range() requires either a single A1 cell
reference (syntax 1) or two A1-style cell references or range
objects (syntax 2). In this case, using Range() is redundant. Try:

Debug.Print Worksheets(glr_CopyWKS).Cells(lngHeader, lngX).Value



In article ,
(Stan Plumber) wrote:

When I run a procedure with this line of code I get the 1004 app
define... error. Yet when I place the cursor over the variables it
references the right worksheet, column, and row. and even the value.
What's wrong with this line of code if:

Debug.Print Worksheets(glr_CopyWKS).Range(Cells(lngHeader,
lngX)).Value

glr_copywks = the activeworksheet
lngheader = a row in the activeworksheet
and lngx = a column in the activeworksheet

TIA

Stan

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
Application-defined or object-defined error Please Help [email protected] Excel Discussion (Misc queries) 1 April 3rd 06 01:00 PM
Application-defined or object-defined error jaf Excel Programming 0 September 8th 03 07:01 PM
Runtime Error 1004 -- Application Defined or Object Defined Error John[_51_] Excel Programming 3 September 4th 03 04:28 PM
VBA - Application-defined or object-defined error Chip Pearson Excel Programming 0 August 24th 03 08:43 PM


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