+ Reply to Thread
Results 1 to 3 of 3

For Each Loop to sort column in multiple sheets

  1. #1
    Registered User
    Join Date
    02-20-2014
    Location
    Washington DC
    MS-Off Ver
    Excel 2010
    Posts
    3

    For Each Loop to sort column in multiple sheets

    Hello, I have a workbook with multiple sheets and all but one of the sheets need to be sorted by date (found in column K). The sheet names vary by week so making this a static reference to a sheet name isn't possible. I'm having a bit of trouble establishing the range that will work with a loop.

    With the code below I'm getting a Run Time Error 1004 saying the sort reference is not valid. I tried removing the ws from in front of the sort range and it works perfectly, but only for a single sheet.

    I'm new to VBA so I apologize if this is easy. I've done many searches and can't find an answer.

    Help please! Thanks!

    Please Login or Register  to view this content.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: For Each Loop to sort column in multiple sheets

    The Key1 range should reference the ws as well.
    key1:=Range("K2"),


    Try this...
    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    02-20-2014
    Location
    Washington DC
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: For Each Loop to sort column in multiple sheets

    Quote Originally Posted by AlphaFrog View Post
    The Key1 range should reference the ws as well.
    key1:=Range("K2"),


    Try this...
    Please Login or Register  to view this content.

    Ah ha! I knew it was something simple that I was forgetting but I just couldn't put my finger on it! Thanks!

+ 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. Macro to loop through multiple sheets
    By excellearner121 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-05-2013, 02:41 AM
  2. [SOLVED] VBA Loop multiple criteria to correct sheets
    By pinstripe05 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-06-2013, 03:07 PM
  3. Loop with AdvancedFilter Using Multiple Sheets
    By freybe06 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-14-2012, 01:10 PM
  4. [SOLVED] Sort by column E, and create sheets named by that column, add header and data
    By salaso69 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-24-2012, 12:42 AM
  5. Using for loop to gather multiple values from different sheets
    By alexwgordon in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-16-2011, 08:08 PM

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