![]() |
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 |
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 |
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 |
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 |
All times are GMT +1. The time now is 07:42 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com