+ Reply to Thread
Results 1 to 5 of 5

VBA Sort Command

  1. #1
    Forum Contributor
    Join Date
    11-08-2012
    Location
    Manchester, UK
    MS-Off Ver
    Excel 2016
    Posts
    140

    VBA Sort Command

    Hello,

    Little help needed on a Sort command within VBA. I have it working within other workbooks but they are defined sheets, for this one I need it to run either on the ActiveSheet or 'fname' which is a variable used to hold the file name.
    Please Login or Register  to view this content.
    I have added a test workbook with some data in order to run and check. It's probably a stupid mistake but I just can't see it.
    Thanking in advance.
    Attached Files Attached Files

  2. #2
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: VBA Sort Command

    rng1, rng2 etc are actual range variables, not the names of ranges, so you just use rng1, not Range("rng1") and so on.
    Rory

  3. #3
    Forum Contributor
    Join Date
    11-08-2012
    Location
    Manchester, UK
    MS-Off Ver
    Excel 2016
    Posts
    140

    Re: VBA Sort Command

    Thanks rorya. Corrected and changed all the 'Range("rng*") to just 'rng*' but still not sorting when the code is run.
    Please Login or Register  to view this content.
    Last edited by mowens74; 09-11-2018 at 09:07 AM. Reason: Added further comments

  4. #4
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: VBA Sort Command

    It does sort for me, although you're treating the first data row as a header row so it won't move.

  5. #5
    Forum Contributor
    Join Date
    11-08-2012
    Location
    Manchester, UK
    MS-Off Ver
    Excel 2016
    Posts
    140

    Re: VBA Sort Command

    Sorted it, I know what the problem was. I used the variable 'rng4', between setting it and using it within the sort code, which changed the range. Something no-one could have helped me with as that code was given on this help request
    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. Include groups of rows in sort command
    By atch-d in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-09-2013, 01:25 PM
  2. [SOLVED] Where is the PivotTable “Sort and Top 10” command ?
    By RogeratCCCC in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 12-26-2012, 01:34 PM
  3. Need to add a sort command to macro
    By ukphoenix in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-02-2008, 10:49 AM
  4. Bringing up sort command
    By don in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-10-2006, 07:55 PM
  5. Sort command does not sort some columns?
    By BillyBob in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 05-11-2006, 11:20 AM
  6. how do i trace back my sort command on a column ?????
    By rp in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 12-01-2005, 09:15 AM
  7. Problem programming the Sort command
    By marshy26 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-28-2005, 10:05 PM
  8. sort command
    By Joe McManemin in forum Excel - New Users/Basics
    Replies: 8
    Last Post: 03-31-2005, 04:06 PM

Tags for this Thread

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