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?
 

Some videos you may like

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

lusov

New Member
Joined
May 17, 2017
Messages
5
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


 

MickG

MrExcel MVP
Joined
Jan 9, 2008
Messages
14,841
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
 

lusov

New Member
Joined
May 17, 2017
Messages
5
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?
 

MickG

MrExcel MVP
Joined
Jan 9, 2008
Messages
14,841
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 ????
 

Watch MrExcel Video

Forum statistics

Threads
1,099,046
Messages
5,466,243
Members
406,474
Latest member
osama beskales

This Week's Hot Topics

Top