+ Reply to Thread
Results 1 to 16 of 16

Using Shapes as Option Buttons

  1. #1
    Registered User
    Join Date
    01-14-2019
    Location
    Oklahoma
    MS-Off Ver
    Excel 2016
    Posts
    16

    Using Shapes as Option Buttons

    My goal is to use shapes as toggle buttons (which when clicked hide/unhide columns/rows) while only allowing one to be on (true or false) at a time. I have code for shapes that I want to use, but I don't know how to tie them together. Also I've got this to work with ActiveX toggle buttons, the code for this is:

    Please Login or Register  to view this content.

    The code for the shape design I have is:

    Please Login or Register  to view this content.
    I'm thinking (guessing) I need to assign Boolean true false values in my shape code and incorporate something similar to this section of my toggle button code:
    Please Login or Register  to view this content.
    I'm very new to VBA, so I might be way off and/or have very inefficient code. Any help is appreciated.

    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #2 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer
    Last edited by 6StringJazzer; 01-30-2019 at 01:07 PM. Reason: code tags; title updated at OP request; add solved to title

  2. #2
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Using Shapes as Toggle Buttons

    Hello jwright2,

    Welcome to the Forum.

    Your post does not comply with Rule 2 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 6)

    Also, please attach a sample workbook (not a picture or pasted copy).

    Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Using Shapes as Toggle Buttons

    I would consider using option buttons instead. It's built-in that only one can be on at a time, and when one is selected it automatically turns of the other one. To do this with shapes or even toggle buttons is a pain and not something I would recommend to someone who is very new at VBA.

    This is what the code for one option button would look like:

    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Registered User
    Join Date
    01-14-2019
    Location
    Oklahoma
    MS-Off Ver
    Excel 2016
    Posts
    16

    Re: Using Shapes as Toggle Buttons

    Thanks 6string for both offering an alternative, pointing out the useless code, and fixing the code tags. I attempted to upload an example document (I didn't see it anywhere in the post), but then tried to remove it, due to it having information in the file properties that I'm not sure I want to post. I'm really fumbling around on this site and VBA adventure as a whole.

    I haven't messed with the option button yet, but I'm assuming I won't be able to customize the appearance any more than an activex toggle button. I have a working document using the toggle buttons already (the option button would have been nice to know about a week ago), but they don't look good enough for my report. I really want to use shapes.

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Using Shapes as Toggle Buttons

    If you can post a file with the sensitive properties removed I can help move you along with what you have. But it would take me too much time to re-create your situation from scratch.

    If you went through the upload process but the file didn't show up it may be that it's too big and you didn't see the message (has happened to me many times). For some reason, we allow zip files that are much larger than .xlsx files, so you might try to zip it then attach it.

    The paper clip icon does not work for attachments. To attach a file, under the text box where you type your reply click the Go Advanced button. On the next screen scroll down and click on Manage Attachments, which will show a pop-up window to Select and Upload a file. Then close the window.

  6. #6
    Registered User
    Join Date
    01-14-2019
    Location
    Oklahoma
    MS-Off Ver
    Excel 2016
    Posts
    16

    Re: Using Shapes as Toggle Buttons

    Ok. I tried to attach an example to the OP and now sending on reply in a zip folder. I don't know how much it will help, but hopefully it will because I gave it a pretty good go at trying to figure this out myself.

    The first tab shows what I need the shapes to be capable of, but using toggle buttons. The other tab shows the format I want the shapes. I think I'm going to rename the thread to "treat shapes as option button" because it seems like that is really the case.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    01-14-2019
    Location
    Oklahoma
    MS-Off Ver
    Excel 2016
    Posts
    16

    Re: Using Shapes as Toggle Buttons

    It's not letting me change the title, I think because of the link in the moderators note, says I need to post more before adding links. I'm just gonna leave it for now. Also I really appreciate any help even if I don't get exactly what I want. I can use it as a resource in the future (like explaining the option button).
    Last edited by jwright2; 01-30-2019 at 10:05 AM.

  8. #8
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Using Shapes as Toggle Buttons

    I have created a shape solution in a new sheet called Using Shapes. All of the code is in Module2.

    To manage two shapes with conceptual on/off states, you have to keep track of their states in a global place. I have declared two Boolean variables at the top of the module to do this.

    I did not know what color you meant for "on" for your shape. In my example brown is "on" and gray is "off". You can reverse them if I got it wrong.

    I created a Sub that formats a shape according to its state. This is called by the Click subs to update the formats of both buttons whenever either one is clicked.

    I added a sub called ShowColumns that updates which columns are visible based on button states.

    Variable rng is declared and set but never used so I removed it.
    Attached Files Attached Files

  9. #9
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Using Shapes as Option Buttons

    I also updated your title, but I'm not sure why you weren't able to.

  10. #10
    Registered User
    Join Date
    01-14-2019
    Location
    Oklahoma
    MS-Off Ver
    Excel 2016
    Posts
    16

    Re: Using Shapes as Option Buttons

    I couldn't change the title due to the link to the rules in the moderator's note. I removed the link, so I could change the title to SOLVED! This looks like exactly what I needed. I will have to play with it quite a bit using it in my report, but I think I have all the tools I need now. Really thank you, this helped a ton.

    -James

  11. #11
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: SOLVED Using Shapes as Option Buttons; removed link in moderator's note

    I did it for you this time, but to mark a thread SOLVED, you don't actually edit the title. Go to the menu immediately above your first post to the thread and click on Thread Tools. From the dropdown menu select "Mark this thread as solved..."

  12. #12
    Registered User
    Join Date
    01-14-2019
    Location
    Oklahoma
    MS-Off Ver
    Excel 2016
    Posts
    16

    Re: SOLVED Using Shapes as Option Buttons; removed link in moderator's note

    Gotcha, I will get better with the rules. Thanks for fixing the mistakes

  13. #13
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: SOLVED Using Shapes as Option Buttons; removed link in moderator's note

    Quote Originally Posted by jwright2 View Post
    Gotcha, I will get better with the rules. Thanks for fixing the mistakes
    NP. We try to be gentle on noobs.

  14. #14
    Registered User
    Join Date
    01-14-2019
    Location
    Oklahoma
    MS-Off Ver
    Excel 2016
    Posts
    16

    Re: SOLVED Using Shapes as Option Buttons; removed link in moderator's note

    Haha we need that. I just re-read the rules and since this is elaborating, I don't think I'm breaking the new help request rule (#4). I have added a third shape button (Red) and noticed if you click the button that is currently selected, all of the other data will show. Is there a way to make all items hidden, or auto select a certain button, if all buttons are turned "off"?

    To illustrate the problem, you can open the attached Excel. Blue is currently "on" the other two are "off", click blue. Now green and red are showing. Now if you click (unselect) green, both blue and red will show. This seems fixable, but nothing I can think of has worked.
    Attached Files Attached Files

  15. #15
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Using Shapes as Option Buttons

    You can't just add more buttons and replicate code; I gave you a two-button solution. The logic needs to be different for more than two buttons. If you click on one button, the logic sets the state of the other button to the opposite. But if you extend this to three buttons, and click on a button to turn it off, you turn the other two on and you don't want more than one one at a time.

    The way option buttons work is if you click one that is Off, it turns On, and the one that is On turns Off. If you click on one that is already On, nothing happens. Is that the model you want to follow with your shape-buttons?

  16. #16
    Registered User
    Join Date
    01-14-2019
    Location
    Oklahoma
    MS-Off Ver
    Excel 2016
    Posts
    16

    Re: Using Shapes as Option Buttons

    Yes, I believe that model will work, as long as I can choose which buttons are tied to each other. My plan is to have multiple shapes as a menu, which are used to select (unhide) which columns of data you see. Then in these columns have a shape or two which will unhide rows to show additional features, so for the shapes that control these rows I would need the associated column button to stay On when the row button is selected On.

    I did try to change the code to a structure similar to my original togglebutton code, thinking I could get all of this to work, but I couldn't. You were right about shapes not being easy for a beginner. If I wasn't clear enough, let me know and I will post an example, or try to clarify better.

+ 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. Can Toggle Buttons control other multiple Toggle Buttons
    By Slurry Pumper in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 07-09-2018, 08:22 AM
  2. [SOLVED] how do i make a toggle button change other toggle buttons value to false
    By kevinu in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-10-2018, 04:19 PM
  3. [SOLVED] Can't Change Visibility of Shapes Border Lines with Toggle Button
    By LokoJoko in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-10-2016, 07:47 AM
  4. [SOLVED] Toggle visibility of shapes via dropdown list between workbooks
    By GuyL23 in forum Excel General
    Replies: 1
    Last Post: 03-07-2014, 07:11 AM
  5. Confused By Toggle Buttons
    By nevi in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-27-2012, 02:19 AM
  6. Toggle Buttons
    By Momo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-09-2005, 10:06 AM
  7. How do I use Toggle Buttons?
    By fuzzyfreak in forum Excel General
    Replies: 0
    Last Post: 01-21-2005, 01:10 PM

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