+ Reply to Thread
Results 1 to 4 of 4

Macro for a button

  1. #1
    Registered User
    Join Date
    01-08-2015
    Location
    Australia
    MS-Off Ver
    Mac 2011
    Posts
    75

    Macro for a button

    Hi,

    I'm wondering if I can use a macro to make a button do different things with each click. I'm wanting to hide/unhide different columns. At the moment I can get it to hide G:BB and then unhide them with the second click. I would prefer it to work as follows

    1st click - hide columns G:BB
    2nd click - hide additional columns C and E
    3rd click - unhide the hidden columns

    I have seen a few posts with private subs so I'm not sure if this is an easier way of doing this but I don't know how to use them.

    Any help would be greatly appreciated.

    Thanks

  2. #2
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Macro for a button

    Why not just use Excel groupings that you can choose to click to expand or contract?
    https://support.office.com/en-us/art...1-be4355959d90


    You CAN use VBA if you wanted but it seems grouping would be more simple.
    Please Login or Register  to view this content.
    Last edited by mikeTRON; 05-13-2016 at 04:46 PM.
    Please ensure you mark your thread as Solved once it is. Click here to see how.
    If a post helps, please don't forget to add to our reputation by clicking the star icon in the bottom left-hand corner of a post.

  3. #3
    Registered User
    Join Date
    01-08-2015
    Location
    Australia
    MS-Off Ver
    Mac 2011
    Posts
    75

    Re: Macro for a button

    Thanks for your help. I am creating something for multiple users and I want it to be as simple as possible to use. There are also multiple sections that will have buttons to perform the same operation. It seems to work although with the second click it hides range C:E but I don't want column D to be hidden. I would like it to leave columns D & F visible. I did play around with changing it to C:C,E:E but it didn't like it the way I changed it. Thanks again

  4. #4
    Registered User
    Join Date
    01-08-2015
    Location
    Australia
    MS-Off Ver
    Mac 2011
    Posts
    75

    Re: Macro for a button

    Didn't really know what I was doing but seem to have got it sorted by playing around with it. Used the following code

    Sub Hide_Unhide()
    If ActiveSheet.Columns("G:BB").Hidden = True And ActiveSheet.Columns("C:C").Hidden = True And ActiveSheet.Columns("E:E").Hidden = True Then
    ActiveSheet.Columns("G:BB").Hidden = False
    ActiveSheet.Columns("C:C").Hidden = False
    ActiveSheet.Columns("E:E").Hidden = False
    Exit Sub
    End If


    If ActiveSheet.Columns("G:BB").Hidden = False Then
    ActiveSheet.Columns("G:BB").Hidden = True
    Else
    ActiveSheet.Columns("C:C").Hidden = True
    ActiveSheet.Columns("E:E").Hidden = True
    End If

    End Sub

+ 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. Automatically add button when data added to cell and apply macro to button?
    By dori2o in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-14-2016, 11:56 AM
  2. Inserting Row Macro using Command Button (ActiveX) relative to Button
    By mebailey in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-12-2016, 09:17 PM
  3. Replies: 30
    Last Post: 11-06-2013, 12:43 PM
  4. [SOLVED] Macro button copies sheet containing a macro button as an image
    By namso1902 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-02-2013, 03:51 PM
  5. Modifying a Macro Button to time stamp when the button was clicked.
    By jonvanwyk in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-22-2010, 04:46 PM
  6. Abort button for a macro(not the break key) and pause/resume button
    By c.vaibhav in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-21-2009, 04:22 AM
  7. A macro to create a form button, assign a macro and name the button
    By cl361 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-11-2008, 01:07 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