How to get row number of the selected cell after on the edit switch in vba

Actually I am creating a list in which there is a edit switch which is toggle able. But now I am wanting that if I on the switch then click any cell then it will display that cells row number. I tried this but it shows the cell address which was active before on the switch. But I want that user will on the switch then which cell will be clicked that cells row number will be in the msgbox.

Here is my tried code -

Private Sub ToggleButton1_Click()


If ToggleButton1.Value = True Then
    MsgBox ActiveCell.Address
Else
    Exit Sub
End If


End Sub

Kindly help!


You need to add worksheet_event code.

You can add that below your button code.

Eg: in the same worksheet code module:

Private Sub ToggleButton1_Click()
End Sub


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If ToggleButton1.Value = True Then MsgBox Target.Row
End Sub