Closed Thread
Results 1 to 9 of 9

Excel 2007 : VBA Sorting Columns in Multiple Worksheets

  1. #1
    Registered User
    Join Date
    12-18-2008
    Location
    Toronto
    MS-Off Ver
    2007
    Posts
    15

    VBA Sorting Columns in Multiple Worksheets

    Good afternoon,

    I am very new to VBA and wanted to understand sorting on multiple worksheets to it's most basic form. I look at previous posts and am completely confused. I am able to sort the active worksheet, but it's not looping to any of the others.

    Any help would be greatly appreciated
    Thanks,
    Mike


    Please Login or Register  to view this content.
    Last edited by Michael Chandrapal; 09-27-2010 at 06:00 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Sorting Columns in Multiple Worksheets

    Break the habit now of "selecting" things in VBA. It's not needed, and in cases like yours actually makes things more difficult.

    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    12-18-2008
    Location
    Toronto
    MS-Off Ver
    2007
    Posts
    15

    Re: Sorting Columns in Multiple Worksheets

    Thank you for your reply Jerry. Works great! Do have a follow up question.

    I thought adding in another level of sorting would have been easy. Unfortunately, not the case. Searched through multiple posts and nothing seems to be working. I tried adding Key 2, Order2 as shown below:

    Please Login or Register  to view this content.
    Column L and BM are both text columns. Not sure why it isn't working, would you be able to help please?

    Thanks,
    Mike

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Sorting Columns in Multiple Worksheets

    Turn on the macro recorder and let it record you sorting the range by the two sets of criteria and then look at the resulting code. You should be able to adjust the code I offered adding in the Key2 and Order2.

    I think the problem is you don't really put a "range" in the Key values, typically, just the cell at the top of the range. Give it a try.

  5. #5
    Registered User
    Join Date
    12-18-2008
    Location
    Toronto
    MS-Off Ver
    2007
    Posts
    15

    Re: Sorting Columns in Multiple Worksheets

    Hi Jerry,

    Recorded the following code. I attempted to incorporate it with your VBA code and nothing seems to be working. I am trying to learn how to do this and don't think going sheet by sheet is the best way. Stumped on this one :s

    Please Login or Register  to view this content.

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Sorting Columns in Multiple Worksheets

    Please Login or Register  to view this content.

    I just noticed you're Excel 2007 is applying some sort of combination of AutoFilter and Sort, something I don't do in Excel 2003, but the code from 2003 for sorting by 2 columns is still pretty basic and works in Excel 2007.

  7. #7
    Registered User
    Join Date
    12-18-2008
    Location
    Toronto
    MS-Off Ver
    2007
    Posts
    15

    Re: Sorting Columns in Multiple Worksheets

    Dynamite!!! Thanks Jerry... Works perfectly!

  8. #8
    Registered User
    Join Date
    12-18-2008
    Location
    Toronto
    MS-Off Ver
    2007
    Posts
    15
    Delete last post.
    Last edited by Michael Chandrapal; 09-28-2010 at 02:54 PM. Reason: Delete Post

  9. #9
    Registered User
    Join Date
    10-06-2018
    Location
    Colorado
    MS-Off Ver
    2007
    Posts
    1

    Re: Excel 2007 : VBA Sorting Columns in Multiple Worksheets

    I just had an application for this, sorting phone numbers, with 4 columns: LD, AC, Prefix, and Nbr.
    After trying the macro recorder, and searching this and other sites, I modified the macro written by the recorder to
    always adjust to the number of lines in my data. The columns are hard-coded, to sort by LD, then AC, then Prefix, and
    then Nbr (columns A through D respectively), and I have the first 2 rows with header information. So, I sort on rows 2
    through the last row, using Row2 2 as a header.

    This may not be exactly what you are looking for, but maybe it will give you a start to be modified.

    Good Luck!

    Code: (My first post, so I hope I did it right. Thanks for any tips, etc.).

    Please Login or Register  to view this content.

Closed 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