Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Run-time error '50290': Application-defined or object-defined erro | Excel Discussion (Misc queries) | |||
Application-defined or object-defined error Please Help | Excel Discussion (Misc queries) | |||
Application-defined or object-defined error | Excel Programming | |||
Runtime Error 1004 -- Application Defined or Object Defined Error | Excel Programming | |||
VBA - Application-defined or object-defined error | Excel Programming |