+ Reply to Thread
Results 1 to 8 of 8

Sorting Columns using Code

  1. #1
    Forum Contributor boylejob's Avatar
    Join Date
    02-22-2007
    Location
    Forest City, NC
    MS-Off Ver
    2003
    Posts
    562

    Sorting Columns using Code

    Good Afternoon,

    I am in need of some help. I have a tab on a worksheet and I would like sort the first 9 columns of information. The sort order is going to by columns I then B then C.

    The macro recorder gave me this
    Please Login or Register  to view this content.
    but I don't want to SELECT anything so I tried rewriting it to this
    Please Login or Register  to view this content.
    where wsList is
    Please Login or Register  to view this content.
    and I end up with an error indicating the sort reference is not valid.

    I am almost positive I have done this before, but I have been unable to locate an example in any of my previously written code. Or I might just have imagined that I have done this before without SELECTING anything.

    Any suggestion?
    Sincerely,
    Jeff

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Jeff,

    Have you checked that the worksheet "List" is the ActiveSheet in the workbook?

    Sincerely,
    Leith Ross

  3. #3
    Forum Contributor boylejob's Avatar
    Join Date
    02-22-2007
    Location
    Forest City, NC
    MS-Off Ver
    2003
    Posts
    562
    Leith,

    Can you make a sheet the active sheet without having to SELECT it?

    It may not be a big deal to select it. When I first joined this forum my goal was to improve the speed at which my code ran. The first thing I was told was to get away from selecting things. I laid that to heart and have pretty much avoided selecting things every since. The speed of my programs increased incredibly.

    This is a single operation so using select is not going to really slow anything down. Just wanted to see if their was another way of doing this.

    Thanks!

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Jeff,

    Is this code in and operating only on the worksheets in the Active Workbook "SEOG Data.xls"?

    Sincerely,
    Leith Ross

  5. #5
    Forum Contributor boylejob's Avatar
    Join Date
    02-22-2007
    Location
    Forest City, NC
    MS-Off Ver
    2003
    Posts
    562
    Leith,

    No, I am currently opening one other workbook and will probably open at least one more before this code is finished.

    Here is all of the code for the subroutine I am working on.
    Please Login or Register  to view this content.
    I definitely appreciate your help on this. Like I mentioned before it is probably no big deal to use select in this case, but I am just wanting to see if there is a way of doing it without selecting. If you think not using select will be more trouble than its worth, just let me know and I'll go ahead and use that.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Jeff,

    I spotted a few things that are causing you problems.

    In this Find routine change the ActiveCell to wsISIR.Cells(1, 1)
    Please Login or Register  to view this content.
    In this Find routine change ActiveCell to wsNCSIG.Cells(1, 1)
    Please Login or Register  to view this content.
    Whenever you open a workbook, that workbook becomes the ActiveWorkbook.
    Please Login or Register  to view this content.
    The code in read can be written as...
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

  7. #7
    Valued Forum Contributor
    Join Date
    08-26-2006
    Location
    -
    MS-Off Ver
    2010
    Posts
    388
    Quote Originally Posted by boylejob View Post
    but I don't want to SELECT anything so I tried rewriting it to this
    Please Login or Register  to view this content.
    and I end up with an error indicating the sort reference is not valid.

    I am almost positive I have done this before, but I have been unable to locate an example in any of my previously written code. Or I might just have imagined that I have done this before without SELECTING anything.

    Any suggestion?
    For the sorting, just a simple amendment is required.
    For each Sort Key, insert the worksheet before each range:
    Please Login or Register  to view this content.
    Then any sheet can be active and nothing needs selecting and the sort will still work.

  8. #8
    Forum Contributor boylejob's Avatar
    Join Date
    02-22-2007
    Location
    Forest City, NC
    MS-Off Ver
    2003
    Posts
    562
    Leith and T_J,

    Thank you so much! Program is working great now!

    I don't know how many times I have stated how much I love this forum. You NEVER EVER visit this forum without learning something new. It is amazing how much better my coding has gotten since joining this forum.

    Thanks again for the help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Nesting (and Sorting) Columns
    By hashcel in forum Excel General
    Replies: 6
    Last Post: 01-31-2008, 10:18 AM
  2. 3 columns; date and two data, problem is sorting and calculating with respect to date
    By phosphorescence in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-29-2008, 04:21 PM
  3. sorting columns from lowest to highest totals
    By tvi569 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-06-2007, 08:41 PM
  4. Problem sorting columns
    By AlanW in forum Excel General
    Replies: 8
    Last Post: 05-21-2007, 12:59 PM
  5. Sorting columns in several worksheets and workbooks
    By Nodles in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-07-2006, 11:35 AM

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