Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Error Handle

I have a marco that helps sort a range of cells, but if a user, choices some
other cells I get an error 'runtime error 1004'

I would like to put some error handling around this, just to say cannot use
this with the cell that they have been selected.

Can anyone help?

Here is the code;

Range("A7:BP150").Select
Selection.Sort Key1:=Range("B7"), Order1:=xlAscending, Header:=xlGuess,
_
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("A7").Select

Thanks Paul



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Error Handle

Paul,

How about avoiding the error, by telling the user
what is going to happen...
'-----------
Sub TestSort()
If MsgBox("This will sort range A7:BP150 only. ", _
vbOKCancel + vbQuestion, " PR did it") = vbCancel Then Exit Sub

Range("A7:BP150").Sort Key1:=Range("B7"), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal

Range("A7").Select
End Sub
'------------

Jim Cone
San Francisco, USA


"PR" wrote in message ...
I have a marco that helps sort a range of cells, but if a user, choices some
other cells I get an error 'runtime error 1004'
I would like to put some error handling around this, just to say cannot use
this with the cell that they have been selected.
Can anyone help?
Here is the code;

Range("A7:BP150").Select
Selection.Sort Key1:=Range("B7"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("A7").Select

Thanks Paul



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Error Handle

Jim,
Thanks for that, and it is a good idea, but I still would like to put a
error handle round it.

PR.

"Jim Cone" wrote in message
...
Paul,

How about avoiding the error, by telling the user
what is going to happen...
'-----------
Sub TestSort()
If MsgBox("This will sort range A7:BP150 only. ", _
vbOKCancel + vbQuestion, " PR did it") = vbCancel Then Exit Sub

Range("A7:BP150").Sort Key1:=Range("B7"), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal

Range("A7").Select
End Sub
'------------

Jim Cone
San Francisco, USA


"PR" wrote in message
...
I have a marco that helps sort a range of cells, but if a user, choices
some
other cells I get an error 'runtime error 1004'
I would like to put some error handling around this, just to say cannot
use
this with the cell that they have been selected.
Can anyone help?
Here is the code;

Range("A7:BP150").Select
Selection.Sort Key1:=Range("B7"), Order1:=xlAscending, Header:=xlGuess,
_
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("A7").Select

Thanks Paul





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Error Handle

PR,

Are you letting the user select the sort range, or will you always
sort only Range("A7:BP150") ?
Is B7 always going to be Key1 and the user can select any range
that encompasses B7 ?

To just in put in error handling, you could do something
like this...
'-------------
Sub TestSort()
On Error GoTo ErrHandler

'Your code...

Exit Sub
ErrHandler:
Beep
MsgBox "Oops - something went wrong with the sort. " & vbCr & _
"Please check the sort area.", vbExclamation, " Blame PR"
End Sub
'-------------

Jim Cone
San Francisco, USA


"PR" wrote in message ...
Jim,
Thanks for that, and it is a good idea, but I still would like to put a
error handle round it.

PR.

"Jim Cone" wrote in message
...
Paul,

How about avoiding the error, by telling the user
what is going to happen...
'-----------
Sub TestSort()
If MsgBox("This will sort range A7:BP150 only. ", _
vbOKCancel + vbQuestion, " PR did it") = vbCancel Then Exit Sub

Range("A7:BP150").Sort Key1:=Range("B7"), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal

Range("A7").Select
End Sub
'------------

Jim Cone
San Francisco, USA


"PR" wrote in message
...
I have a marco that helps sort a range of cells, but if a user, choices
some
other cells I get an error 'runtime error 1004'
I would like to put some error handling around this, just to say cannot
use
this with the cell that they have been selected.
Can anyone help?
Here is the code;

Range("A7:BP150").Select
Selection.Sort Key1:=Range("B7"), Order1:=xlAscending, Header:=xlGuess,
_
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("A7").Select

Thanks Paul





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
handle error in IF ELSEIF statement Sabosis Excel Worksheet Functions 1 April 30th 09 05:06 AM
How do I handle error conditions with the FIND command? mywebaccts (at) PLUGcomcast.net Excel Worksheet Functions 6 August 5th 07 12:14 AM
How to handle error 8007000e Memory Error L. A. M. Excel Programming 6 June 28th 05 04:05 AM
How to make error handle for mis-typed variable? RB Smissaert Excel Programming 22 May 1st 05 10:33 PM


All times are GMT +1. The time now is 11:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"