#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 171
Default Stop

I always seem to come across interesting things as I make up new
workbooks. I'm using the following code to allow user to step to the
left:

ActiveCell.Offset(0, -1).Select

Butt when user gets to A1, if the button is pushed again by accident,
an error box comes up because the first cell is reached:

Run-time error '1004': Application-defined or object-defined error

Is there any way to stop this error popping up? Any advice re this?
Even a message saying "you can't go any further to the left", heck,
whatever works <g.

Thanks. :oD

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Stop

maybe this

Sub test()
If ActiveCell.Column < 1 Then
ActiveCell.Offset(0, -1).Select
End If
end sub
--


Gary


"StargateFan" wrote in message
...
I always seem to come across interesting things as I make up new
workbooks. I'm using the following code to allow user to step to the
left:

ActiveCell.Offset(0, -1).Select

Butt when user gets to A1, if the button is pushed again by accident,
an error box comes up because the first cell is reached:

Run-time error '1004': Application-defined or object-defined error

Is there any way to stop this error popping up? Any advice re this?
Even a message saying "you can't go any further to the left", heck,
whatever works <g.

Thanks. :oD



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Stop

You have 2 options:
- Check where the active cell is first.
If ActiveCell.Column 1 Then ActiveCell.Offset(0, -1).Select

- Do it anyway and ignore the error, as (in this case) no damage is done or
propagated by the error.
On Error Resume Next
ActiveCell.Offset(0, -1).Select
On Error GoTo 0

NickHK

"StargateFan" wrote in message
...
I always seem to come across interesting things as I make up new
workbooks. I'm using the following code to allow user to step to the
left:

ActiveCell.Offset(0, -1).Select

Butt when user gets to A1, if the button is pushed again by accident,
an error box comes up because the first cell is reached:

Run-time error '1004': Application-defined or object-defined error

Is there any way to stop this error popping up? Any advice re this?
Even a message saying "you can't go any further to the left", heck,
whatever works <g.

Thanks. :oD



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 171
Default Stop

On Thu, 12 Apr 2007 00:21:55 -0400, "Gary Keramidas"
<GKeramidasATmsn.com wrote:

maybe this

Sub test()
If ActiveCell.Column < 1 Then
ActiveCell.Offset(0, -1).Select
End If
end sub


Super. It seems to work perfectly. I keep going left till it stops
yet no error comes up which is great.

Thanks. :oD

Gary


"StargateFan" wrote in message
.. .
I always seem to come across interesting things as I make up new
workbooks. I'm using the following code to allow user to step to the
left:

ActiveCell.Offset(0, -1).Select

Butt when user gets to A1, if the button is pushed again by accident,
an error box comes up because the first cell is reached:

Run-time error '1004': Application-defined or object-defined error

Is there any way to stop this error popping up? Any advice re this?
Even a message saying "you can't go any further to the left", heck,
whatever works <g.

Thanks. :oD

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 171
Default Stop

On Thu, 12 Apr 2007 12:31:55 +0800, "NickHK"
wrote:

You have 2 options:
- Check where the active cell is first.
If ActiveCell.Column 1 Then ActiveCell.Offset(0, -1).Select

- Do it anyway and ignore the error, as (in this case) no damage is done or
propagated by the error.
On Error Resume Next
ActiveCell.Offset(0, -1).Select
On Error GoTo 0


Thanks!

What is the difference, pls, between the 2nd code above and Gary's
solution?

Sub test()
If ActiveCell.Column < 1 Then
ActiveCell.Offset(0, -1).Select
End If
end sub

Thanks. :oD

NickHK

"StargateFan" wrote in message
.. .
I always seem to come across interesting things as I make up new
workbooks. I'm using the following code to allow user to step to the
left:

ActiveCell.Offset(0, -1).Select

Butt when user gets to A1, if the button is pushed again by accident,
an error box comes up because the first cell is reached:

Run-time error '1004': Application-defined or object-defined error

Is there any way to stop this error popping up? Any advice re this?
Even a message saying "you can't go any further to the left", heck,
whatever works <g.

Thanks. :oD




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Stop

The 2nd option executes the code anyway, but any error raised is simply
ignored and code continues.

In Gary's code, the potentially error causing is not executed if it would
raise an error.

NickHK

"StargateFan" wrote in message
...
On Thu, 12 Apr 2007 12:31:55 +0800, "NickHK"
wrote:

You have 2 options:
- Check where the active cell is first.
If ActiveCell.Column 1 Then ActiveCell.Offset(0, -1).Select

- Do it anyway and ignore the error, as (in this case) no damage is done

or
propagated by the error.
On Error Resume Next
ActiveCell.Offset(0, -1).Select
On Error GoTo 0


Thanks!

What is the difference, pls, between the 2nd code above and Gary's
solution?

Sub test()
If ActiveCell.Column < 1 Then
ActiveCell.Offset(0, -1).Select
End If
end sub

Thanks. :oD

NickHK

"StargateFan" wrote in message
.. .
I always seem to come across interesting things as I make up new
workbooks. I'm using the following code to allow user to step to the
left:

ActiveCell.Offset(0, -1).Select

Butt when user gets to A1, if the button is pushed again by accident,
an error box comes up because the first cell is reached:

Run-time error '1004': Application-defined or object-defined error

Is there any way to stop this error popping up? Any advice re this?
Even a message saying "you can't go any further to the left", heck,
whatever works <g.

Thanks. :oD




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
How stop the "started office live" pop-up to stop. it is checked yrose24 Excel Discussion (Misc queries) 1 September 2nd 09 03:32 PM
Stop % in red Mark Excel Worksheet Functions 7 December 4th 04 01:36 PM
How do I stop other circles in other cells to stop selecting? stauff Excel Worksheet Functions 2 October 29th 04 09:02 PM
How do I stop other circles in other boxes to stop selecting? stauff Excel Worksheet Functions 1 October 28th 04 10:27 PM
Macro: With Stop it works. Without Stop it doesn't. Don Wiss Excel Programming 2 October 12th 04 10:49 AM


All times are GMT +1. The time now is 08:06 PM.

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"