+ Reply to Thread
Results 1 to 5 of 5

Using a control's name dynamically in a piece of code

  1. #1
    Registered User
    Join Date
    06-14-2006
    Posts
    13

    Using a control's name dynamically in a piece of code

    Hey everyone,

    I've currently got this code:

    Please Login or Register  to view this content.
    The CommandButtons hide the rows just underneath the button. As you can see, with only 5 buttons the code is already getting bigger. This will only get worse and the whole file will have hundres of buttons.

    Is there a way to pass the name of the CommandButton clicked to the code so I don't need to duplicate the code for every new button?

    Something like this semantic definition:

    Please Login or Register  to view this content.
    Any suggestions would be great!! Thanks.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,475
    Hi,
    That's a lot of work maintaining hudreds of buttons,possibly one button would be required only.
    Please Login or Register  to view this content.
    and a global unhide code to reset the worksheet..
    Please Login or Register  to view this content.
    What kind of information do you want to extract?

  3. #3
    Registered User
    Join Date
    06-14-2006
    Posts
    13
    I actually found a way to do it dynamically and quickly across all sheets, anywhere on the page:

    Please Login or Register  to view this content.
    I chopped it together from snippets on the web, works perfectly. Now I want to create a "hide all" button that will trigger, for example, the five buttons to the right of it.

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    You might want to switch to buttons from the Forms menu if you are going to have them all call the same routine. Forms buttons do not need to pass through a _Click event, they can call the routine directly.

    Like Dave, I suggest that you use code to choose the cells to hide/unhide rather than running everything through buttons and their location.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    Registered User
    Join Date
    06-14-2006
    Posts
    13
    Hi, Thanks for the reply.

    All of the buttons are Form buttons not ActiveX controls. This means that I only have to give each button an individual name and it will work perfectly. So far I've copied the original set of 5 buttons about 6 times, and simply incrementing the number in the button's name makes it work.

    Now all I need is that 'hide all' button for each set of five buttons. When I hit that I want it to trigger the 5 buttons to its right, or if that's too hard, 5 specific button names. How is that done?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Placement of a particular line of code
    By smurray444 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-19-2007, 11:15 AM
  2. Running code while displaying a UserForm with vbModeless
    By PilgrimTim in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-06-2007, 08:08 AM
  3. automated code for handling events in a dynamically created sheet -- possible?
    By francoiss in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-09-2007, 12:18 AM
  4. Check cell contents
    By nabialekp in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-15-2006, 12:55 AM
  5. Code help appreciated:Code runs fine
    By peter.thompson in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-22-2006, 10:03 PM

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