Cell and command button
Cell and command button
(OP)
Was wondering if anyone has ever had the experience when clicking a command button that it will fill in a cell( e.g. A1) with the name of a command button that was pressed (e.g. HC12).
Thanks all
Thanks all





RE: Cell and command button
One way is to assign a different (but similar) subroutine to each button. When the button is clicked it writes the desired text to the cell A1.
A nicer way is to assign one subroutine to all the applicable command buttons. Name the buttons for easier identification. Example subroutine:
Sub buttonSmart()
ActiveSheet.Cells(1, 1) = Application.Caller
End Sub
RE: Cell and command button
Private Sub HC12_Click()
Range("A11").Select
ActiveCell.FormulaR1C1 = "1"
Range("A43").Select
ActiveCell.FormulaR1C1 = "1"
Range("A53").Select
ActiveCell.FormulaR1C1 = "1"
Range("A67").Select
ActiveCell.FormulaR1C1 = "1"
Range("A123").Select
ActiveCell.FormulaR1C1 = "1"
Range("A166").Select
ActiveCell.FormulaR1C1 = "1"
Range("A168").Select
ActiveCell.FormulaR1C1 = "1"
Range("A184").Select
ActiveCell.FormulaR1C1 = "1"
Range("A194").Select
ActiveCell.FormulaR1C1 = "1"
Range("A2").Select
End Sub
_________________________________________________________
Sub buttonSmart()
ActiveSheet.Cells(1, 1) = Application.Caller
End Sub
So this would automatically look at the command button properties look at the (Name) field and place it in Column 1 Row 1. Am I understanding this correctly?
RE: Cell and command button
CODE
Range("A11,A43,A53,A67,A123,A168,A184,A194").Value = 1
Range("A1") = HC12.Name
End Sub
RE: Cell and command button
Thanks so much Cummings54