+ Reply to Thread
Results 1 to 5 of 5

Cant't get Code to sort named Range when looping through worksheets.

  1. #1
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,397

    Cant't get Code to sort named Range when looping through worksheets.

    Need to loop through range of worksheets, sorting and copying rows meeting various criteria.

    First Code works perfectly because it names the specific worksheet to sort:

    Please Login or Register  to view this content.
    But as it needs to loop through each worksheet except those Named, I adapted it.
    Problem is the Code throws a Runtime Error 1004 when asked to set the SORT RANGE of whichever worksheet is being worked on:

    Please Login or Register  to view this content.
    All solutions, suggestion and alternatives welcome as ever.

    Ochimus
    Last edited by Ochimus; 03-28-2024 at 05:50 AM.

  2. #2
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,980

    Re: Cant't get Code to sort named Range when looping through worksheets.

    Try adding a dot to qualify this


    Please Login or Register  to view this content.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,446

    Re: Cant't get Code to sort named Range when looping through worksheets.

    Fast answers need visual help. Please read the yellow banner at the top of this page on how to attach a file and a mocked up solution.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,397

    Re: Cant't get Code to sort named Range when looping through worksheets.

    ByteMarks,

    Many thanks for prompt suggestion, but unfortunately adding the dot hasn't solved the problem.

    TMS,

    Apologies, hadn't noticed the Workbook had not attached (Hazard of working all hours!). It is now.

    "Should be" worksheet shows what the output should be, enabling the PIVOT Table and SLICERS in Cols U - AB.

    Objective is to loop through each Monthly worksheet, sort the data by the first revenue stream (Col K) and post the details of that bloc, putting the revenue in Col L of the MASTER worksheet, adding the Revenue stream Name in Col K, then repeat sorting by Col L (Copies to next free row of MASTER), then Col N. Result is all three Streams are listed sequentially in one column.

    Problem is the Code generates an Error when I define the Range to copy across.

    Please Login or Register  to view this content.
    As before, all solutions, suggestion and alternatives welcome as ever.

    Ochimus
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,980

    Re: Cant't get Code to sort named Range when looping through worksheets.

    Does this work for you?

    Please Login or Register  to view this content.

+ 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. [SOLVED] Custom Sort looping through worksheets and workbook
    By Andy15 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-14-2017, 04:04 PM
  2. [SOLVED] vba code to add modulable no of named worksheets after the last existing named sheet
    By JEAN1972 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-11-2017, 08:48 AM
  3. Looping Mutliple Named Resized Ranges in next empty row below another named range
    By gingumdog in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-19-2014, 08:15 PM
  4. Sort Worksheets based on a Named Range
    By K m in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 03-10-2014, 04:09 PM
  5. [SOLVED] Looping through worksheets defined in named range
    By boon-yao.tek in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 08-22-2013, 02:16 AM
  6. Named Range - looping through each cell
    By leshka_uk in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-12-2012, 06:16 AM
  7. Looping a Named Range
    By Paluee in forum Excel General
    Replies: 6
    Last Post: 02-25-2010, 03:18 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