+ Reply to Thread
Results 1 to 7 of 7

Why One Macro Works and The Other Doesnt?

  1. #1
    Registered User
    Join Date
    08-23-2012
    Location
    Earth
    MS-Off Ver
    Excel 2007
    Posts
    14

    Why One Macro Works and The Other Doesnt?

    Does anyone see why this Macro doesnt work?

    I have two Macros. One created Through the Recorder, the other Taken from the net and tweaked a bit.
    I am trying to get the to sort the worksheet by color.

    Macro 1: This one works fine. (Generated from the recorder)
    Please Login or Register  to view this content.
    This One as taken from the net and Worked Awsome for Selecting the cells I wanted, but doesnt make it to the sorting, it errors out with:
    Run Time error '1004'
    The Sort reference is not valid. Make sure that its within the data you want to sort, and the first Sort By box isnt the same or blank
    This happens as soon as I run the .Apply line:

    Here is the code:
    Please Login or Register  to view this content.
    Any Ideas? I even tried pasting the exact code from the Recorded Macro right after "myUsedRange.Select" and got the same error.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Why One Macro Works and The Other Doesnt?

    try this
    Please Login or Register  to view this content.
    otherwise attach your file
    If solved remember to mark Thread as solved

  3. #3
    Registered User
    Join Date
    08-23-2012
    Location
    Earth
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Why One Macro Works and The Other Doesnt?

    Nope, sorry, this doesnt work. I get another runtime error. This time on: Set Rng = ActiveSheet.Selection.
    test.xlsm
    Last edited by changedsoul; 08-30-2012 at 08:15 PM.

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,430

    Re: Why One Macro Works and The Other Doesnt?

    Selection is a property of the activewindow.
    Also the modify the SortFields to be a single column and not the whole range.

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  5. #5
    Registered User
    Join Date
    08-23-2012
    Location
    Earth
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Why One Macro Works and The Other Doesnt?

    Ahhh Thanks for pointing that out to me. After looking at the Auto generated macro from the recorder, I noticed the range was only in column A. The changes worked perfectly. Thanks again.

  6. #6
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Why One Macro Works and The Other Doesnt?

    @ changedsoul

    Based on your last post it seems that you are satisfied with the solution(s) you've received but you haven't marked your thread as SOLVED. I'll do that for you now but please keep in mind for your future threads that Rule #9 requires you to do that yourself. If your problem has not been solved you can use Thread Tools (located above your first post) and choose "Mark this thread as unsolved".
    Thanks.

    Also, as a new member of the forum, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

  7. #7
    Registered User
    Join Date
    08-23-2012
    Location
    Earth
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Why One Macro Works and The Other Doesnt?

    I wasnt aware of that, thats for pointing it out. I will do what you suggested.

+ 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