ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Error Not Displaying, Instead macro just ends (https://www.excelbanter.com/excel-programming/395470-error-not-displaying-instead-macro-just-ends.html)

J@Y

Error Not Displaying, Instead macro just ends
 
I have this code which runs, it encounters an error, then the program just
stops. It doesn't give me any messages. I had to use On error goto ErrH,
ErrH: Debug.Print Err to find out there was an Error. The error was 424,
Object undefined. I even put On error goto 0 before the code, but it still
doesn't display a error message for me.

Trevor Shuttleworth

Error Not Displaying, Instead macro just ends
 
Might help if you posted (all) the code

Regards

Trevor


"J@Y" wrote in message
...
I have this code which runs, it encounters an error, then the program just
stops. It doesn't give me any messages. I had to use On error goto ErrH,
ErrH: Debug.Print Err to find out there was an Error. The error was 424,
Object undefined. I even put On error goto 0 before the code, but it still
doesn't display a error message for me.




J@Y

Error Not Displaying, Instead macro just ends
 
Apparently the code causing problems was the following:

If Not Cel2 is Nothing then
.......
endif

Cel2 was Uninitialized. I only had Public Cel2 in the beginning. However I
have Option Explicit, so how come no error came of this?

Trevor Shuttleworth

Error Not Displaying, Instead macro just ends
 
As far as I know, "Public Cel2" would be equivalent to "Dim Cel2 as
Variant".

Hence the Option Explicit would have no complaint.

If you haven't initialised it, it would contain nothing so it would execute
the code.

Regards

Trevor


"J@Y" wrote in message
...
Apparently the code causing problems was the following:

If Not Cel2 is Nothing then
......
endif

Cel2 was Uninitialized. I only had Public Cel2 in the beginning. However I
have Option Explicit, so how come no error came of this?




Dave Peterson

Error Not Displaying, Instead macro just ends
 
If you used:

Public Cel2 as range
'or even
'Public cel2 as object

Then you could check to see if that range object (or any object) is nothing
with:

if Not (cel2 is nothing) then



But using
Public Cel2 'as Variant
then cel2 would be empty

so you'd use:
if cel2 = empty then

But it's much better to declare your variables with the correct type (As Range,
As Long, As Worksheet, ...)

Because if you assign a range to that variable:

dim cel2 as variant
set cel2 = activesheet.range("a1")
if cel2 = empty then

would be testing to see if the value of the cell is empty.





J@Y wrote:

Apparently the code causing problems was the following:

If Not Cel2 is Nothing then
......
endif

Cel2 was Uninitialized. I only had Public Cel2 in the beginning. However I
have Option Explicit, so how come no error came of this?


--

Dave Peterson

J@Y

Error Not Displaying, Instead macro just ends
 
That's what I thought. If it was nothing, then the code should continue. But
the whole macro stops at the "If Not Cel2 is Nothing then" line, which is
what is confusing me.

"Trevor Shuttleworth" wrote:

As far as I know, "Public Cel2" would be equivalent to "Dim Cel2 as
Variant".

Hence the Option Explicit would have no complaint.

If you haven't initialised it, it would contain nothing so it would execute
the code.

Regards

Trevor


"J@Y" wrote in message
...
Apparently the code causing problems was the following:

If Not Cel2 is Nothing then
......
endif

Cel2 was Uninitialized. I only had Public Cel2 in the beginning. However I
have Option Explicit, so how come no error came of this?






All times are GMT +1. The time now is 10:24 AM.

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