[Solved] VBA: Excel Toggling

  • I would like to create a toggle button that allows me to alternately sort a small 8 column database base by 1 of 2 columns. Run the macro once, sort by entity. Run it again, sort by %. Any help would be greatly appreciated.

  • Hi scojax22 and welcome to the Ozgrid Forums.


    You can create a toggle button thru View-Toolbars-ControlToolbox then click on the design-mode icon, then the Toggle button icon and place & size the toggle button onto your sheet. Turn off design mode.


    Paste the code below into your worksheet's code module


    Private Sub ToggleButton1_Click()
    If ToggleButton1.Value = True Then
    'do this code
    Else
    'do this other code
    End If
    End Sub


    Let us know if you need clarification or help with the macro.

  • Thanks. Your code answered my question! Now my problem is the sizing and resizing of the text on the button. When I press the button, the text is fine, but when I click back on the sheet, the text shrinks, although the button stays the same (correct) size. I know how to format buttons from the forms menu, but this ActiveX button is a bit different. Thanks, again.


    Scott

  • I hadn't noticed that before. It seems to happen only when the zoom is reduced (ie 75%).
    You can change font size by right clicking on the button when you are in design mode. This will pull up the Properties window that has a font attribute line. You could also try resizing button (bigger).

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!