Select the cell that a button is in
Solved/Closed
Related:
- Excel button to go to cell
- At button - Guide
- Number to words in excel - Guide
- How to answer call with volume button android - Guide
- How to reset ps4 controller without reset button - Guide
- How to take screenshot in excel - Guide
2 responses
rizvisa1
Posts
4478
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
May 5, 2022
766
May 24, 2011 at 01:05 PM
May 24, 2011 at 01:05 PM
With all credit to Tom Urtis from mrexcel
Depends on if the button is from the control toolbox or the Forms toolbar.
Depends on if the button is from the control toolbox or the Forms toolbar.
'If forms, this macro assigned to that button: Sub test() MsgBox ActiveSheet.Buttons(Application.Caller).TopLeftCell.Row End Sub 'if CommandButton, this macro assigned to that button: Private Sub CommandButton1_Click() MsgBox CommandButton1.TopLeftCell.Row End Sub
It is a form control from the developer ribbon that I inserted. I then assigned this macro:
Sub VernTest()
'
' VernTest Macro
' Select cells in current row
'
'
With ActiveCell
Range(Cells(.Row, "B"), Cells(.Row, "U")).Select
End With
End Sub
This macro selects the appropriate cells, but in whatever row that has the active cell.
I'm not sure how to include your command into this macro.
Also, I tried your solutions above, but couldn't get either to work.
I appreciate your help so fast! Thanks!
Sub VernTest()
'
' VernTest Macro
' Select cells in current row
'
'
With ActiveCell
Range(Cells(.Row, "B"), Cells(.Row, "U")).Select
End With
End Sub
This macro selects the appropriate cells, but in whatever row that has the active cell.
I'm not sure how to include your command into this macro.
Also, I tried your solutions above, but couldn't get either to work.
I appreciate your help so fast! Thanks!
rizvisa1
Posts
4478
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
May 5, 2022
766
May 24, 2011 at 01:33 PM
May 24, 2011 at 01:33 PM
First you have to know what kind of button you have used.
The sample code that Tom had, was just a message box to tell you what row the button is
in your case you would have grab the row
some thing like this (assuming you have used a form button)
The sample code that Tom had, was just a message box to tell you what row the button is
in your case you would have grab the row
some thing like this (assuming you have used a form button)
Sub VernTest() ' ' VernTest Macro ' Select cells in current row Dim lRow As Long lRow = ActiveSheet.Buttons(Application.Caller).TopLeftCell.Row Range(Cells(lRow, "B"), Cells(lRow, "U")).Select End Sub