+ Reply to Thread
Results 1 to 3 of 3

Toggle Button & getting the postion of the just pressed button

  1. #1
    Registered User
    Join Date
    06-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    2

    Toggle Button & getting the postion of the just pressed button

    All,

    I have a spreadsheet of say 1000 columns split into groups of 25. The first of each group simply sums the rows of the other 24 cols. We will call the 1st col of each 25 the primary col whilst all the other are secondary.

    If I put a toggle button at the top of the primary column, I can by linking this to the same cell use a macro to hide / unhide all the secondary columns tied to the primary column. This works
    But there are approx 50 buttons required all with apart from the name and the function that returns the position of the linked cell identical macros. If I copy a button the copy remains linked to the same cell as the master button and there is a blank macro associated with it.

    Option 1: Create 50 buttons, macros manually - boring
    Option 2: Create 50 buttons with identical macros all of which pass parameters to a master macro that does the hiding etc. However this relies on one of two things:
    a. Each button has to be manually linked to a cell - so the ActiveCell.Column returns the column that the button is in. I could then use the position of the button to define which is the primary column and then hide the next 24 columns
    b. Manually edit each button with a linked cell

    What I would like to do is copy and paste the buttons and then use something to get the position of the button, rather than any linked cell. I can generate the short stub macros easily that just pass parameters to the primary macro.

    Any ideas how to persuade a button to return its current column location when its cliicked, without having to link a cell or anything custom?

    Regards

    Sean

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Toggle Button & getting the postion of the just pressed button

    Sean,

    If you're using a toggle button, then it's an ActiveX control. For the task you're trying to do, I would recommend a Form Control, and just use a regular button instead of a toggle button.

    When the secondary columns are currently visible, the button's text would be "Hide", and when the secondary columns are currently hidden, the button's text would be "Show". So to get this working, unhide all columns, create a button with text "Hide", and assign it to the following macro in a standard module:
    Please Login or Register  to view this content.


    Then, just copy/paste the button
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Registered User
    Join Date
    06-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Toggle Button & getting the postion of the just pressed button

    Well that works beautifully.

    Unfortunately I have no idea how..... I am reading it with a completely blank expression

    But thank you - thats saved me hours

    Sean

+ 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