ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Range(0,0).Select ? (https://www.excelbanter.com/excel-programming/348100-range-0-0-select.html)

Bill Martin[_2_]

Range(0,0).Select ?
 
I have a macro I inherited with the code fragment below. I find that if I
comment out the "on error" statement, the program fails at the line
"Range(0,0).Select" with the Run-time error '1004': Method 'Range' of object
'_Global' failed.

Excel seems to think the Range line causes a error, yet if I comment out the
Range line, the program fails to work so it is apparently doing *something*.
The error handler simply says Resume Next so it's not doing anything obvious (to
me anyhow).

On Error GoTo ErrorHandler
... (many lines of code) ...
Set DataSheet = ActiveSheet
DataSheet.Unprotect
Range(0, 0).Select

Can someone explain to me the logic of this fragment? I've been unsuccessful
with the Excel Help system and with my normal reference books. I would have
thought it was just the equivalent of Range("A1").select, but apparently not.

Thanks...

Bill

RB Smissaert

Range(0,0).Select ?
 
These 2 statements can work:

Range(Cells(1), Cells(1)).Select

Cells(1, 1).Select

But I don't think Range(0, 0).Select can ever work.

Maybe show all the code.


RBS




"Bill Martin" wrote in message
...
I have a macro I inherited with the code fragment below. I find that if I
comment out the "on error" statement, the program fails at the line
"Range(0,0).Select" with the Run-time error '1004': Method 'Range' of
object
'_Global' failed.

Excel seems to think the Range line causes a error, yet if I comment out
the
Range line, the program fails to work so it is apparently doing
*something*.
The error handler simply says Resume Next so it's not doing anything
obvious (to
me anyhow).

On Error GoTo ErrorHandler
... (many lines of code) ...
Set DataSheet = ActiveSheet
DataSheet.Unprotect
Range(0, 0).Select

Can someone explain to me the logic of this fragment? I've been
unsuccessful
with the Excel Help system and with my normal reference books. I would
have
thought it was just the equivalent of Range("A1").select, but apparently
not.

Thanks...

Bill



Charlie

Range(0,0).Select ?
 
Range(0, 0).Select is incorrect for two reasons:

1) Excel sheets are "one-based", i.e. cell "A1" is equivalent to Cells(1, 1)

2) The Range statement cannot reference cells by row and column number, use
the Cells statement instead:

Cells(1, 1)
not
Range(1, 1)

The On Error Resum Next statment simply ignores the erroneous line and
continues to the next line of code. I think the intention here was to reset
the cursor to cell A1. Change the erroneous line to:

Range("A1").Select


"Bill Martin" wrote:

I have a macro I inherited with the code fragment below. I find that if I
comment out the "on error" statement, the program fails at the line
"Range(0,0).Select" with the Run-time error '1004': Method 'Range' of object
'_Global' failed.

Excel seems to think the Range line causes a error, yet if I comment out the
Range line, the program fails to work so it is apparently doing *something*.
The error handler simply says Resume Next so it's not doing anything obvious (to
me anyhow).

On Error GoTo ErrorHandler
... (many lines of code) ...
Set DataSheet = ActiveSheet
DataSheet.Unprotect
Range(0, 0).Select

Can someone explain to me the logic of this fragment? I've been unsuccessful
with the Excel Help system and with my normal reference books. I would have
thought it was just the equivalent of Range("A1").select, but apparently not.

Thanks...

Bill


Bill Martin[_2_]

Range(0,0).Select ?
 
Thanks to both of you who responded. I'm quite willing to accept that the line
is incorrect -- I just didn't have the confidence to declare it as such myself!

Thanks...

Bill
--------------------------
Charlie wrote:
Range(0, 0).Select is incorrect for two reasons:

1) Excel sheets are "one-based", i.e. cell "A1" is equivalent to Cells(1, 1)

2) The Range statement cannot reference cells by row and column number, use
the Cells statement instead:

Cells(1, 1)
not
Range(1, 1)

The On Error Resum Next statment simply ignores the erroneous line and
continues to the next line of code. I think the intention here was to reset
the cursor to cell A1. Change the erroneous line to:

Range("A1").Select


"Bill Martin" wrote:


I have a macro I inherited with the code fragment below. I find that if I
comment out the "on error" statement, the program fails at the line
"Range(0,0).Select" with the Run-time error '1004': Method 'Range' of object
'_Global' failed.

Excel seems to think the Range line causes a error, yet if I comment out the
Range line, the program fails to work so it is apparently doing *something*.
The error handler simply says Resume Next so it's not doing anything obvious (to
me anyhow).

On Error GoTo ErrorHandler
... (many lines of code) ...
Set DataSheet = ActiveSheet
DataSheet.Unprotect
Range(0, 0).Select

Can someone explain to me the logic of this fragment? I've been unsuccessful
with the Excel Help system and with my normal reference books. I would have
thought it was just the equivalent of Range("A1").select, but apparently not.

Thanks...

Bill


Chip Pearson

Range(0,0).Select ?
 
Range(0, 0).Select

It is bad code. The syntax

Range(x,y)

will fail if x and y are any numbers.




--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Bill Martin" wrote in message
...
I have a macro I inherited with the code fragment below. I find
that if I
comment out the "on error" statement, the program fails at the
line
"Range(0,0).Select" with the Run-time error '1004': Method
'Range' of object
'_Global' failed.

Excel seems to think the Range line causes a error, yet if I
comment out the
Range line, the program fails to work so it is apparently doing
*something*.
The error handler simply says Resume Next so it's not doing
anything obvious (to
me anyhow).

On Error GoTo ErrorHandler
... (many lines of code) ...
Set DataSheet = ActiveSheet
DataSheet.Unprotect
Range(0, 0).Select

Can someone explain to me the logic of this fragment? I've
been unsuccessful
with the Excel Help system and with my normal reference books.
I would have
thought it was just the equivalent of Range("A1").select, but
apparently not.

Thanks...

Bill





All times are GMT +1. The time now is 07:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com