ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Never used a button before (https://www.excelbanter.com/excel-programming/413788-never-used-button-before.html)

Max

Never used a button before
 
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?

Jim Thomlinson

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?


Tom Ogilvy

Never used a button before
 
what does the VBA screen say? (assume you mean it give you an error message).

Also, what version of excel are you using.

--
Regards,
Tom Ogilvy


"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?


Dave Peterson

Never used a button before
 
It sounds like you may be still in design mode.

If you're using xl2003 menus, there's a design mode icon on the Control toolbox
toolbar. Click that to toggle in and out of that state.

Private Sub CommandButton2_Click()
With me.range("F9")
.ColorIndex = 43
.Pattern = xlSolid
End With
End Sub

(dropping the selection.)


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?


--

Dave Peterson

Tom Ogilvy

Never used a button before
 
Good catch. I guess he meant double clicked the button.

--
Regards,
Tom Ogilvy


"Jim Thomlinson" wrote:

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?


Jim Thomlinson

Never used a button before
 
That is my best guess. Nice to have you back. We missed you. General
interest... Where did you get to. Somewhere good I hope.
--
HTH...

Jim Thomlinson


"Tom Ogilvy" wrote:

Good catch. I guess he meant double clicked the button.

--
Regards,
Tom Ogilvy


"Jim Thomlinson" wrote:

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?


Tom Ogilvy

Never used a button before
 
Jim,
I didn't go anywhere - specifically I didn't go here <g

--
Regards,
Tom Ogilvy


"Jim Thomlinson" wrote:

That is my best guess. Nice to have you back. We missed you. General
interest... Where did you get to. Somewhere good I hope.
--
HTH...

Jim Thomlinson


"Tom Ogilvy" wrote:

Good catch. I guess he meant double clicked the button.

--
Regards,
Tom Ogilvy


"Jim Thomlinson" wrote:

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?


Jim Thomlinson

Never used a button before
 
You took a break from answering questions??? My sense of world order is
feeling a bit off knowing that. Death, taxes and Tom will answer the question
before you do. There are so few things you can count on in the world... <g
--
HTH...

Jim Thomlinson


"Tom Ogilvy" wrote:

Jim,
I didn't go anywhere - specifically I didn't go here <g

--
Regards,
Tom Ogilvy


"Jim Thomlinson" wrote:

That is my best guess. Nice to have you back. We missed you. General
interest... Where did you get to. Somewhere good I hope.
--
HTH...

Jim Thomlinson


"Tom Ogilvy" wrote:

Good catch. I guess he meant double clicked the button.

--
Regards,
Tom Ogilvy


"Jim Thomlinson" wrote:

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?


Harald Staff[_2_]

Never used a button before
 
Great seeing you again, Tom :-)

Best wishes Harald

"Tom Ogilvy" wrote in message
...
Jim,
I didn't go anywhere - specifically I didn't go here <g

--
Regards,
Tom Ogilvy




All times are GMT +1. The time now is 05:09 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com