+ Reply to Thread
Results 1 to 4 of 4

VBA button that changes label when click ie. expand, collapse

  1. #1
    Registered User
    Join Date
    01-30-2014
    Location
    Melbourne
    MS-Off Ver
    Excel 2003
    Posts
    4

    VBA button that changes label when click ie. expand, collapse

    Hi Guys,

    Ive got some code which will toggle hide and unhide rows, thats fine.

    Sub transaction1()
    Rows("7:9").Hidden = Not Rows("7:9").Hidden
    End Sub

    How ever I would like the macro button to change labels when clicked. Ie Expand when hidden and Collapse when unhidden.

    Can you help please ?
    Ive search high and low and although simple cannot find a direct answer.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,457

    Re: VBA button that changes label when click ie. expand, collapse

    I use this code to hide or show some worksheets:

    Please Login or Register  to view this content.

    Use the button's caption to indicate its state. If, when you press it, it says "hide", you hide the rows and set it to "show".

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    01-30-2014
    Location
    Melbourne
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: VBA button that changes label when click ie. expand, collapse

    Quote Originally Posted by TMShucks View Post
    I use this code to hide or show some worksheets:

    Please Login or Register  to view this content.

    Use the button's caption to indicate its state. If, when you press it, it says "hide", you hide the rows and set it to "show".

    Regards, TMS

    _________________


    Hi Thanks for the quick response. I couldn't get it to work unfortunately. I'm just a beginner at VBA atm. Do you post the code in a module? Can you advise how I can assign the button to it. Sorry for being a noob.

    I just need it to hide and unhide certain rows (from a button) when the button is clicked I want the button to be named "collapse" to hide the rows and when clicked again to be named "expand"

    thanks again

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,457

    Re: VBA button that changes label when click ie. expand, collapse

    This is probably a case of "you show me yours ..."

    It's button code so it would go in the worksheet where the button is.

    Post a sample workbook.

    Regards, TMS

+ 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. Single click to expand / collapse Tree structure in VBE Watch window, Possible?
    By Xceller in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-10-2014, 09:04 PM
  2. How change label value for each click button ??
    By WILKER in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 11-02-2012, 12:25 PM
  3. Toggling Button Labels Between Expand/Collapse
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-27-2012, 08:09 AM
  4. [SOLVED] expand and collapse button with subtotals
    By TUNGANA KURMA RAJU in forum Excel General
    Replies: 1
    Last Post: 05-06-2006, 08:20 AM
  5. expand/collapse row button
    By caii in forum Excel General
    Replies: 3
    Last Post: 10-26-2005, 05:05 AM

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