+ Reply to Thread
Results 1 to 4 of 4

Error Handle

  1. #1
    PR
    Guest

    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. #2
    Jim Cone
    Guest

    Re: 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" <paul.raeburn@ntlworld.com> wrote in message news:eLQRusenFHA.3120@TK2MSFTNGP09.phx.gbl...
    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. #3
    PR
    Guest

    Re: 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" <jim.coneXXX@rcn.comXXX> wrote in message
    news:uzVKuDfnFHA.3300@TK2MSFTNGP15.phx.gbl...
    > 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" <paul.raeburn@ntlworld.com> wrote in message
    > news:eLQRusenFHA.3120@TK2MSFTNGP09.phx.gbl...
    > 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. #4
    Jim Cone
    Guest

    Re: 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" <paul.raeburn@ntlworld.com> wrote in message news:%23f$G1HfnFHA.3408@tk2msftngp13.phx.gbl...
    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" <jim.coneXXX@rcn.comXXX> wrote in message
    news:uzVKuDfnFHA.3300@TK2MSFTNGP15.phx.gbl...
    > 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" <paul.raeburn@ntlworld.com> wrote in message
    > news:eLQRusenFHA.3120@TK2MSFTNGP09.phx.gbl...
    > 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1