+ Reply to Thread
Results 1 to 9 of 9

Sorting CommandButtons

  1. #1
    Registered User
    Join Date
    04-02-2013
    Location
    belgium
    MS-Off Ver
    Excel 2010
    Posts
    16

    Sorting CommandButtons

    Hi,

    I started 2 days to work with VBA so everything i accomplished till now is because of help here on this forum.
    Thanks for that

    Now my problem.
    Im trying to sort a collum of commandbuttons by the captionname without changing the macro of that button.
    after searching on this forum I found this thread:
    http://www.excelforum.com/excel-prog...ext-label.html

    I copy'ed the macro there:
    now when I try to run this I get an error and the next line turns yellow: ReDim arrBtns(1 To BtnCount)

    Thanks in advantage for ur time!
    greetz
    Last edited by ikkuh; 04-08-2013 at 06:04 AM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Sorting CommandButtons

    Hello ikkuh,

    Welcome to the Forum!

    The error indicates there are no Forms buttons on the worksheet. There are 2 types of buttons: Forms and ActiveX. If you post a copy of your workbook then I verify the problem and correct it.

    To Post Your Workbook
    1. At the bottom right of the Reply window, Click the button Go Advanced
    2. At the top of the Your Message Window, in the first row of icons, Click the Paperclip icon.
    3. Click the Add Files button at the top right in the dialog box. This displays the File Manager dialog.
    4. Click the Select Files button at the bottom middle of the dialog.
    5. In the new window Find the file you want to upload, select it, and Click Open.
    6. You will now be back in the File Manager dialog. Click the bottom Middle button Upload File.
    7. Wait until the file has completely uploaded before you exit the File Manager dialog.

    File Manger Picture
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    04-02-2013
    Location
    belgium
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Sorting CommandButtons

    Hi,

    Thanks for the fast reposonse. I indeed used active X buttons. Is there a diffrence between the 2?
    This is not the exactly same file but it is a copy of that worksheet, only the names changed because i don't know the company wants me
    to share that list.
    The is on difference. In the real file I programmed the buttons to have the same name as a list a few worksheets later.

    thanks for the help!


    Edit: the home button and the other sort button doesn't need to be sorted. so only B7-B81 can that maybe be the problem?
    Thanks!
    Attached Files Attached Files
    Last edited by ikkuh; 04-04-2013 at 02:33 AM.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Sorting CommandButtons

    Hello ikkuh,

    Here is the updated macro. This macro works with the ActiveX Command Buttons only. The previous code works with Forms CommandButtons.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    04-02-2013
    Location
    belgium
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Sorting CommandButtons

    Thanks alot! works great!

  6. #6
    Registered User
    Join Date
    04-02-2013
    Location
    belgium
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Sorting CommandButtons

    Hi

    thanks again for your help!
    But this brings me to the next problem.
    I programmed the buttons to take their name from a list a few worksheets further but that list has also some empty cells so the captionname so some buttons have no name. If i press sort the empty ones go to the top.
    Is there a way to sort A-> Z with the blank cells at the bottom?

    I also copyd this list in another list on another wortksheet with the form: ='Nieuwe machine'!B7:C7.
    So the blank cells in the main list give on this list a 0 and same here i made a sort button but if I press it the 0's will go to the top.

    Thanks in advance!

    Greetings
    Ikkuh

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Sorting CommandButtons

    Hello Ikkuh,

    Here is revised macro to sort the ActiveX Command Buttons in ascending order (A to Z) with the blank buttons at the bottom.
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    04-02-2013
    Location
    belgium
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Sorting CommandButtons

    Hi,

    Thanks for your time.
    For some reason it doesn't sort the list if I add new objects?

    Greetings
    Ikkuh

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Sorting CommandButtons

    Hello ikkuh,

    Can you post the workbook you are problems with?

  10. #10
    Registered User
    Join Date
    04-02-2013
    Location
    belgium
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Sorting CommandButtons

    Hi,

    Thanks Leith Ross!

    It works it was some stupid mistake I made!
    ps: sorry for the late response I was out of town this weekend.

    greetz
    Ikkuh

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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