Selected Answer
Hi Orkrj.
If your button is placed on Sheet1, then the click macro will be "behind" Sheet1 in Visual Basic.
If (in Design mode) you right-click the button and select "View Code", Visual Basic will show something like:
Private Sub CommandButton1_Click()
End Sub
That is where the code is! You need to write your code there e.g.
Private Sub CommandButton1_Click()
MsgBox "Today's date is " & Format(Date, "dddd mmm dd, yyyy"
End Sub
If you then return to Sheet1 and (out of Design mode) click the button, that code will run.
If however you have existing code in Private Sub CommandButton1_Click that calls another procedure (e.g called "MyButton") and you don't know where that is:
- in the Visual Basic code, select the text MyButton or whatever it's called
- in the Visual Basic menu bar, pick Edit/ Find...
- in the Find requestor that pops up, click Current Project then FindNext (perhaps more than once)
VB should then locate any places MyButton is used including Sub MyButton() -where the appropriate location e.g. Module1 (rather than Sheet1) will show as greyed in the VB Project window.
Hope this makes sense and helps. If so. please remember to mark this Answer as Selected (or choose WillieD24's Answer if that solves things better).