+ Reply to Thread
Results 1 to 31 of 31

Help! The recorded Macro does not work for the highlighted

  1. #1
    Registered User
    Join Date
    09-18-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    17

    Help! The recorded Macro does not work for the highlighted

    Please Login or Register  to view this content.
    Last edited by Cutter; 09-18-2012 at 07:48 PM. Reason: Added code tags

  2. #2
    Registered User
    Join Date
    09-18-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Help! The recorded Macro does not work for the highlighted

    The recorded codes work if I use absolute references to record, but I have to use relative reference since the total records are changing.

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

    Re: Help! The recorded Macro does not work for the highlighted

    @ lans_bazx

    Welcome to the forum.

    Please notice that code tags have been added to your post(s). The forum rules require them so please keep that in mind and add them yourself whenever showing code in any of your future posts. To see instructions for applying them, click on the Forum Rules button at the top of the page and read Rule #3.
    Thanks.

  4. #4
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,519

    Re: Help! The recorded Macro does not work for the highlighted

    Try this

    Please Login or Register  to view this content.
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  5. #5
    Registered User
    Join Date
    09-18-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Help! The recorded Macro does not work for the highlighted

    Thank you very much Mike and Cutter for your help

    but when I add the codes, it still give me debug message

    Can you debug these codes for me? Thanks in advance.

    Please Login or Register  to view this content.

  6. #6
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,519

    Re: Help! The recorded Macro does not work for the highlighted

    How about this

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    09-18-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Help! The recorded Macro does not work for the highlighted

    Hi Mike,

    This time the debug highlighted as these codes:
    Please Login or Register  to view this content.

  8. #8
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,519

    Re: Help! The recorded Macro does not work for the highlighted

    Ok give this a try. I took out all the Activecell.select offset stuff


    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    09-18-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Help! The recorded Macro does not work for the highlighted

    Hi Mike,

    It works this time, but I want to sort the records by the 2nd column which it's column b. Could you please help me change it?
    I just started read the vba book, and try the recorder to solve my problem. I have to learn how to use variables.

  10. #10
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,519

    Re: Help! The recorded Macro does not work for the highlighted

    Just change the Key.
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    09-18-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Help! The recorded Macro does not work for the highlighted

    Hi Mike,

    It works So, how do I sort without the last row?

  12. #12
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,519
    What do you mean?

  13. #13
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,519

    Re: Help! The recorded Macro does not work for the highlighted

    Add a -1 to the end of this line

    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    09-18-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Help! The recorded Macro does not work for the highlighted

    I would sort all the rows but not the last row. that's why I recorded as following:
    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    09-18-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Help! The recorded Macro does not work for the highlighted

    I just re-run it, and it's still include the lastrow in sort. that means the last row is not keep in last row instead it's in the middle of the sort.

  16. #16
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,519

    Re: Help! The recorded Macro does not work for the highlighted

    This will work

    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    09-18-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Help! The recorded Macro does not work for the highlighted

    Sorry Mike, it's still include the last row in sort

  18. #18
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,519

    Re: Help! The recorded Macro does not work for the highlighted

    Can you upload you workbook?

  19. #19
    Registered User
    Join Date
    09-18-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Help! The recorded Macro does not work for the highlighted

    How do i do that?

  20. #20
    Registered User
    Join Date
    09-18-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Help! The recorded Macro does not work for the highlighted

    Please Login or Register  to view this content.

  21. #21
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,519

    Re: Help! The recorded Macro does not work for the highlighted

    At the bottom where you see Go Advanced click that then scroll down to Manage Attachments.

  22. #22
    Registered User
    Join Date
    09-18-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Help! The recorded Macro does not work for the highlighted

    I just learned to attache a fiel
    Attached Files Attached Files

  23. #23
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,519

    Re: Help! The recorded Macro does not work for the highlighted

    see if this works for you. Its working for me. I did notice that you had SetRange Range("A1:D" & Lastrow) and your data goes to column E

    Please Login or Register  to view this content.

  24. #24
    Registered User
    Join Date
    09-18-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Help! The recorded Macro does not work for the highlighted

    This time it shows syntax error

  25. #25
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,519

    Re: Help! The recorded Macro does not work for the highlighted

    What error is it giving? What Line has the error?
    Witht the workbook you uploaded and the code in post #23 it runs like it should on my end.

  26. #26
    Registered User
    Join Date
    09-18-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Help! The recorded Macro does not work for the highlighted

    Hi Mike
    Thanks for ur help. I can't use Internet on my computer. I am using cell phone to do it now. It s very slow . I will try it again tonight

  27. #27
    Registered User
    Join Date
    09-18-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Help! The recorded Macro does not work for the highlighted

    Hi Mike
    Thanks for ur help. I can't use Internet on my computer. I am using cell phone to do it now. It s very slow . I will try it again tonight

  28. #28
    Registered User
    Join Date
    09-18-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Help! The recorded Macro does not work for the highlighted

    I just compared ur latest two posts. The only difference is the range. Don't know why the sort part is in red color which shows syntax error

  29. #29
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,519

    Re: Help! The recorded Macro does not work for the highlighted

    Here I added the code to your last workbook you uploaded and it works for me.
    test.xlsm

  30. #30
    Registered User
    Join Date
    09-18-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Help! The recorded Macro does not work for the highlighted

    Hi Mike,

    I just tested the latest codes again.
    The sort result shows the last row is another number instead of 599999.

  31. #31
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,519

    Re: Help! The recorded Macro does not work for the highlighted

    What version of Excel are you running?

    The sort result shows the last row is another number instead of 599999
    Is this with the attatched workbook or are you running this on another workbook?

+ 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