+ Reply to Thread
Results 1 to 9 of 9

Sort using VBA giving error.....please help

  1. #1
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Sort using VBA giving error.....please help

    I am doing this sort in VBA and i keep getting this error

    "The sort reference is not valid. Make sure that its within the data you want to sort and the first sory by box isnt the same or blank.



    Please Login or Register  to view this content.


    i am at a loss. My data table is A1:U1145.

    sort_col1 = 1
    sort_col2=20
    sort_col3=21

    please help!

  2. #2
    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
    48,335

    Re: Sort using VBA giving error.....please help

    Can we see the workbook with this code in it? With some sample data?

    I'd want to step through and see what was in the variables.

    Regards
    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


  3. #3
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Re: Sort using VBA giving error.....please help

    i wish i could post the data.........but i cant right now

    I did do a macro record and then put this into the code and it worked.......take a look . any ideas on why this worked please please please please let me know!!!!!!!!!!!!!! I just cant figure it out.


    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Re: Sort using VBA giving error.....please help

    here is the same code but with a few variable names

    Please Login or Register  to view this content.

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,990

    Re: Sort using VBA giving error.....please help

    Original code should have been:
    Please Login or Register  to view this content.
    so that all Range calls are qualified with the worksheet.
    Everyone who confuses correlation and causation ends up dead.

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Sort using VBA giving error.....please help

    Please Login or Register  to view this content.
    PS. Please do not use 'Help'or 'Please' in the threadtitle. The readability of your post won't be improved by using an abundance of exclamationsigns either.
    Last edited by snb; 05-19-2011 at 11:22 AM.



  7. #7
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Re: Sort using VBA giving error.....please help

    Romperstomper,

    YOU ARE THE MAN!!!!!!!!!!

    Thanks to all who tried to help much appreicated!!!!!!!!!!!!

    It worked......i added the with and end-with (ie...i added the code you suggested) and it worked!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!



    THANKS!

  8. #8
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Re: Sort using VBA giving error.....please help

    snb,

    sorry i wont use such language again.......i was just really frustrated........but again sorry!


    Also the code from snb works great as well!

    THANKS GUYS!

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,990

    Re: Sort using VBA giving error.....please help

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

+ Reply to 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