Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
handle error in IF ELSEIF statement | Excel Worksheet Functions | |||
How do I handle error conditions with the FIND command? | Excel Worksheet Functions | |||
How to handle error 8007000e Memory Error | Excel Programming | |||
How to make error handle for mis-typed variable? | Excel Programming |