View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson Jim Thomlinson is offline
external usenet poster
 
Posts: 5,939
Default Never used a button before

So you grabbed a button off of the control toolbox and placed it on your
sheet. You recorded a macro and copied the code that was recorded into the
command button's click event. (you got the click event code stub by double
clicking the command button) I assume that my description is accurate so far?
When you added the button your sheet is in Design Mode. That mode allows you
to interact with the button without triggering the code to run. In order to
make the button operable you need to exit design mode. The first button on
the control toolbox looks like a triangle and ruler. Click that button to
exit design mode. Your button should now work correctly. You could tighten up
your code a bit as follows if you want...

Private Sub CommandButton2_Click()
'does not select the cell
With Range("F9").Interior
.ColorIndex = 43
.Pattern = xlSolid
End With
End Sub

--
HTH...

Jim Thomlinson


"max" wrote:

I've inserted a command button and recorded (very simple):

Private Sub CommandButton2_Click()

Range("F9").Select
With Selection.Interior
.ColorIndex = 43
.Pattern = xlSolid
End With
End Sub

When I click the button, it takes me to the VBA screen. what am I doing
wrong?