+ Reply to Thread
Results 1 to 19 of 19

sort columns with macro button

  1. #1
    Forum Contributor
    Join Date
    08-19-2012
    Location
    Sydney
    MS-Off Ver
    MS Office 365/16
    Posts
    282

    sort columns with macro button

    Hi all,

    I am trying to create a macro button to sort my columns out. One column needs to be sorted in Alphabetical order. The next column needs to be sorted highest to lowest number, with the 1st column as the added level (2nd option).

    If you see the attached filed hopefully you can see what I am trying to get at.

    Many thanks.
    Attached Files Attached Files

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: sort columns with macro button

    Is this the same question as http://www.excelforum.com/excel-prog...t-columns.html ?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Forum Contributor
    Join Date
    08-19-2012
    Location
    Sydney
    MS-Off Ver
    MS Office 365/16
    Posts
    282

    Re: sort columns with macro button

    it is slightly different that's why I thought it is best i make a new thread. The previous one was about sorting the columns out without sorting other columns. This one is sorting columns out while keeping the other columns aligned with each other. Hope this makes sense.

  4. #4
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: sort columns with macro button

    Try this...

    Please Login or Register  to view this content.


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  5. #5
    Forum Contributor
    Join Date
    08-19-2012
    Location
    Sydney
    MS-Off Ver
    MS Office 365/16
    Posts
    282

    Re: sort columns with macro button

    Is this an Active X button called SortData?

  6. #6
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: sort columns with macro button

    SortData is the name I have given to that code. You can change it to whatever name you would like to have...

    ActiveX button needs the code called or pasted inside the command button code.

    Form button just needed to assign the macro with it.

    So choose the one which you would like to have...

  7. #7
    Forum Contributor
    Join Date
    08-19-2012
    Location
    Sydney
    MS-Off Ver
    MS Office 365/16
    Posts
    282

    Re: sort columns with macro button

    Ok i have managed to sort it out. The only issue I have is in Column B and C (see attached) I want it to go from the highest to lowest with the blank cells underneath it.
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    08-19-2012
    Location
    Sydney
    MS-Off Ver
    MS Office 365/16
    Posts
    282

    Re: sort columns with macro button

    I have uploaded another updated version. Hopefully this explains more of what I am looking for.

    Thanks in advance.
    Attached Files Attached Files

  9. #9
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: sort columns with macro button

    maybe so
    Try to double-click in the green cells of line 12.
    I changed the formula in columns B and C (in yellow), make the same changes to the other columns.
    You can also use the ListObject with alternating rows instead of conditional formatting.
    Attached Files Attached Files

  10. #10
    Forum Contributor
    Join Date
    08-19-2012
    Location
    Sydney
    MS-Off Ver
    MS Office 365/16
    Posts
    282

    Re: sort columns with macro button

    Thanks Nilem,

    I am having a bit of trouble with it. I went to transfer the code over to my actual file and its doesn't seem to work. From my understanding it is because I have the columns from my proper document starting from column B not A. I tried to change the code but it didn't work for me.

    Thanks.

  11. #11
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: sort columns with macro button

    attach a new example with the real location of the data

  12. #12
    Forum Contributor
    Join Date
    08-19-2012
    Location
    Sydney
    MS-Off Ver
    MS Office 365/16
    Posts
    282

    Re: sort columns with macro button

    Hope this is ok?

    Thanks as always
    Attached Files Attached Files

  13. #13
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: sort columns with macro button

    try (see attachment)
    Attached Files Attached Files

  14. #14
    Forum Contributor
    Join Date
    08-19-2012
    Location
    Sydney
    MS-Off Ver
    MS Office 365/16
    Posts
    282

    Re: sort columns with macro button

    Nilem,

    Thank you so much. That works really well.

    I hate to be a pain, but this has now caused another issue. I have attached my proper document. You will notice in column A i have other buttons. Now when i go to use them there seems to be a conflict.

    Also just on another not when I double click column C it moves the empty cells to the top.

    Thanks.
    Attached Files Attached Files

  15. #15
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: sort columns with macro button

    Simply declare the variables in each procedure of Sheet4 module: Dim i as Long
    Change formulas to sorting occurred correctly (see post 9),
    replace =IF($H13=0,"",IF($B13="","",... with =IF($H13="",0,IF($B13="",0,... (i.e. 0 instead of "")

  16. #16
    Forum Contributor
    Join Date
    08-19-2012
    Location
    Sydney
    MS-Off Ver
    MS Office 365/16
    Posts
    282

    Re: sort columns with macro button

    Hi. Sorry. This is what I did. I am obviously missing something.

    Please Login or Register  to view this content.

  17. #17
    Forum Contributor
    Join Date
    08-19-2012
    Location
    Sydney
    MS-Off Ver
    MS Office 365/16
    Posts
    282

    Re: sort columns with macro button

    Hi Nilem,

    Any luck in finding out in the above code what I am doing wrong as it is still not working for me.

    Thanks

  18. #18
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: sort columns with macro button

    Hi Sirdon
    I rewrote procedures in the 'batting_statistics' list module and ThisWorkbook module
    see attachment
    Attached Files Attached Files

  19. #19
    Forum Contributor
    Join Date
    08-19-2012
    Location
    Sydney
    MS-Off Ver
    MS Office 365/16
    Posts
    282

    Re: sort columns with macro button

    nilem...you are a legend...thank you so, so much. I really appreciate it.

+ 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