Several Toggle Buttons with same Macros

lusov

New Member
Joined
May 17, 2017
Messages
5
Hi I have created a code for a Toggle button. However I need 50+ toggle buttons in the file with the same code.
Please, see the code below.

Private Sub ToggleButton1_Click()
If ToggleButton1.Value = True Then
ToggleButton1.Value. Caption = "Include"
Range ("I5"). Value = 1
Else
ToggleButton1.Value. Caption = "Exclude"
Range ("I5"). Value = 0
End If

End Sub

I also need the I5 cell to change according to row number of Toggle Button.

Can you, please, help me with this?
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Sorry I have a type there

[h=2][/h]
Private Sub ToggleButton1_Click()
If ToggleButton1.Value = True Then
ToggleButton1. Caption = "Include"
Range ("I5"). Value = 1
Else
ToggleButton1. Caption = "Exclude"
Range ("I5"). Value = 0
End If

End Sub


 
Upvote 0
Perhaps this:-
Code:
Private Sub ToggleButton1_Click()
 With ToggleButton1
    If .Value = True Then
        .Caption = "Include"
        Cells(.TopLeftCell.Row, "I") = 1
    Else
        .Caption = "Exclude"
        Cells(.TopLeftCell.Row, "I") = 0
    End If
End With
End Sub
 
Upvote 0
Perhaps this:-
Code:
Private Sub ToggleButton1_Click()
 With ToggleButton1
    If .Value = True Then
        .Caption = "Include"
        Cells(.TopLeftCell.Row, "I") = 1
    Else
        .Caption = "Exclude"
        Cells(.TopLeftCell.Row, "I") = 0
    End If
End With
End Sub

Hi Thanks a lot it worked. Only I don't know how to apply the same code to several toggle buttons with different names. Can you help me with that as well?
 
Upvote 0
Not quite sure what the problem is,
To cover a number of buttons, you need to do this manually, by just inserting the same code in each "Toggle" button, you could possible do this with code , but for 50 buttons its not really worth it.
Perhaps your problem is something else ????
 
Upvote 0

Forum statistics

Threads
1,214,914
Messages
6,122,211
Members
449,074
Latest member
cancansova

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top