+ Reply to Thread
Results 1 to 8 of 8

Sort without Selecting

  1. #1
    ssjody
    Guest

    Sort without Selecting

    My current code for Sorting selects the sheet, sorts the data then
    returns back to my Data Entry sheet. How can I have this perform this
    without the code selecting the sheet? I just want it to happen in the
    background without the sheets flashing back and forth while this
    happens.

    I did a search and found some suggestions but can't find one that works
    for my application.

    Thanks Jody

    ' SortcpModels
    Sheets("cpModels").Select
    Columns("A:B").Select
    Selection.Sort Key1:=Range("A2"), Order1:=xlAscending,
    Header:=xlGuess, _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal
    Sheets("Data Entry").Select
    Range("B3").Select


  2. #2
    Chip Pearson
    Guest

    Re: Sort without Selecting

    Jody,

    Try

    Sheets("cpModels").Range("A:B").Sort Key1:=Range("A2"), _
    Order1:=xlAscending, Header:=xlGuess, _
    OrderCustom:=1, MatchCase:=False

    --
    Cordially,
    Chip Pearson
    Microsoft MVP - Excel
    Pearson Software Consulting, LLC
    www.cpearson.com




    "ssjody" <jbprather@fuse.net> wrote in message
    news:1135093832.451483.321820@g47g2000cwa.googlegroups.com...
    > My current code for Sorting selects the sheet, sorts the data
    > then
    > returns back to my Data Entry sheet. How can I have this
    > perform this
    > without the code selecting the sheet? I just want it to happen
    > in the
    > background without the sheets flashing back and forth while
    > this
    > happens.
    >
    > I did a search and found some suggestions but can't find one
    > that works
    > for my application.
    >
    > Thanks Jody
    >
    > ' SortcpModels
    > Sheets("cpModels").Select
    > Columns("A:B").Select
    > Selection.Sort Key1:=Range("A2"), Order1:=xlAscending,
    > Header:=xlGuess, _
    > OrderCustom:=1, MatchCase:=False,
    > Orientation:=xlTopToBottom, _
    > DataOption1:=xlSortNormal
    > Sheets("Data Entry").Select
    > Range("B3").Select
    >




  3. #3
    ssjody
    Guest

    Re: Sort without Selecting

    Works! Thanks Chip

    Jody


  4. #4
    Peter Rooney
    Guest

    RE: Sort without Selecting

    Hi, Jody,

    Thjere are lots of ways you can sort more efficiently, without selecting
    forst:

    Sub Macro5()
    Range("B11:T17").Sort Key1:=Range("B12"), Order1:=xlAscending,
    Header:=xlGuess, _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal
    End Sub

    I find it easier to give range names to header cells in your database, so,
    id you insert or delete rows, your code always points to the same cell.

    In the above example, you could replays Range("B12") with
    Range("SalesColHeader") for example, where SalesColHeader is a name applied
    to cell B12.

    I always call the first field header "DatabaseStart", thus the above example
    would begin:
    Range("DatabaseStart").Sort Key1

    Hope this is of some use

    Happy Christmas

    Pete



    "ssjody" wrote:

    > My current code for Sorting selects the sheet, sorts the data then
    > returns back to my Data Entry sheet. How can I have this perform this
    > without the code selecting the sheet? I just want it to happen in the
    > background without the sheets flashing back and forth while this
    > happens.
    >
    > I did a search and found some suggestions but can't find one that works
    > for my application.
    >
    > Thanks Jody
    >
    > ' SortcpModels
    > Sheets("cpModels").Select
    > Columns("A:B").Select
    > Selection.Sort Key1:=Range("A2"), Order1:=xlAscending,
    > Header:=xlGuess, _
    > OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    > DataOption1:=xlSortNormal
    > Sheets("Data Entry").Select
    > Range("B3").Select
    >
    >


  5. #5
    ssjody
    Guest

    Re: Sort without Selecting

    Thanks Pete! That makes good sense. I can use that.

    Jody


  6. #6
    Dave Peterson
    Guest

    Re: Sort without Selecting

    I think this is my current "standard" for sorting.

    ' SortcpModels
    with Sheets("cpModels")
    with .range("a:b")
    .sort key1:=.columns(1), order1:=xlascending, _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal
    end with
    end with

    I like that I can use .columns(1) to specify the key(s).

    ssjody wrote:
    >
    > My current code for Sorting selects the sheet, sorts the data then
    > returns back to my Data Entry sheet. How can I have this perform this
    > without the code selecting the sheet? I just want it to happen in the
    > background without the sheets flashing back and forth while this
    > happens.
    >
    > I did a search and found some suggestions but can't find one that works
    > for my application.
    >
    > Thanks Jody
    >
    > ' SortcpModels
    > Sheets("cpModels").Select
    > Columns("A:B").Select
    > Selection.Sort Key1:=Range("A2"), Order1:=xlAscending,
    > Header:=xlGuess, _
    > OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    > DataOption1:=xlSortNormal
    > Sheets("Data Entry").Select
    > Range("B3").Select


    --

    Dave Peterson

  7. #7
    Chip Pearson
    Guest

    Re: Sort without Selecting

    There is a bug in my code. It should be

    Sheets("cpModels").Range("A:B").Sort
    Key1:=Sheets("cpModels").Range("A2"), _
    Order1:=xlAscending, Header:=xlGuess, _
    OrderCustom:=1, MatchCase:=False

    --
    Cordially,
    Chip Pearson
    Microsoft MVP - Excel
    Pearson Software Consulting, LLC
    www.cpearson.com



    "Chip Pearson" <chip@cpearson.com> wrote in message
    news:OlBjW%23XBGHA.3604@TK2MSFTNGP09.phx.gbl...
    > Jody,
    >
    > Try
    >
    > Sheets("cpModels").Range("A:B").Sort Key1:=Range("A2"), _
    > Order1:=xlAscending, Header:=xlGuess, _
    > OrderCustom:=1, MatchCase:=False
    >
    > --
    > Cordially,
    > Chip Pearson
    > Microsoft MVP - Excel
    > Pearson Software Consulting, LLC
    > www.cpearson.com
    >
    >
    >
    >
    > "ssjody" <jbprather@fuse.net> wrote in message
    > news:1135093832.451483.321820@g47g2000cwa.googlegroups.com...
    >> My current code for Sorting selects the sheet, sorts the data
    >> then
    >> returns back to my Data Entry sheet. How can I have this
    >> perform this
    >> without the code selecting the sheet? I just want it to happen
    >> in the
    >> background without the sheets flashing back and forth while
    >> this
    >> happens.
    >>
    >> I did a search and found some suggestions but can't find one
    >> that works
    >> for my application.
    >>
    >> Thanks Jody
    >>
    >> ' SortcpModels
    >> Sheets("cpModels").Select
    >> Columns("A:B").Select
    >> Selection.Sort Key1:=Range("A2"), Order1:=xlAscending,
    >> Header:=xlGuess, _
    >> OrderCustom:=1, MatchCase:=False,
    >> Orientation:=xlTopToBottom, _
    >> DataOption1:=xlSortNormal
    >> Sheets("Data Entry").Select
    >> Range("B3").Select
    >>

    >
    >




  8. #8
    Registered User
    Join Date
    07-12-2017
    Location
    Boston, MA
    MS-Off Ver
    2010
    Posts
    1

    Red face Re: Sort without Selecting

    Thanks, this was super helpful! I had some linked sheets and the data needed to be sorted properly in the Data sheet in order for the rest of them to work, this macro applied to all those tabs made the file much easier to hand off.

+ 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