×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Cell and command button

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

RE: Cell and command button

You are wishing to do this?

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

(OP)
Ok, let me just understand this.  So if I press the command button that has a label HC12 (Which has a macro)

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

You are better off getting your command button to what you want directly in the command button code.  This makes application maintenance staight forward.  I've rewriten your sample code with the statement needed to place the button name on your worksheet.  HTH

CODE

Private Sub HC12_Click()
  Range("A11,A43,A53,A67,A123,A168,A184,A194").Value = 1
  Range("A1") = HC12.Name
End Sub

RE: Cell and command button

(OP)
OK, thanks for really condensing my macro... It works exactly as I wanted it to....

Thanks so much Cummings54

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources