Invoke a macro with a command button

K

kim s

Excel 2007:

I've written a macro which I can run with the shortcut key but when I attach
it to a button it gives me an error on the line: Rows(3:3).Select

Is there a property that has to be set for the button to make it run the
macro?

I have been using Excell 2003 and hadn't used Excel 2007 until somemone new
arrrived and the system they set up for her had the new version and I don't
have a manual for it.
 
J

Jim Rech

Your code should be Rows(3).Select I think.

--
Jim
| Excel 2007:
|
| I've written a macro which I can run with the shortcut key but when I
attach
| it to a button it gives me an error on the line: Rows(3:3).Select
|
| Is there a property that has to be set for the button to make it run the
| macro?
|
| I have been using Excell 2003 and hadn't used Excel 2007 until somemone
new
| arrrived and the system they set up for her had the new version and I
don't
| have a manual for it.
 
K

kim s

Thank you, I will try that; I have access to the particular system after
hours so it will be a while before I can try it.

But I do wonder why it works as a macro when I run it using the shortcut key
I've set up. I ran it and tested it before I attached it ot the button so I
thought it would run; also, I developed the macro originally by using the
"Record macro" feature so the syntax should have been correct.
 
J

Jim Rech

But I do wonder why it works as a macro when I run it using the shortcut
Maybe you typed the code in to your post rather than copy/paste?

Rows(3:3).Select is not valid in any version. Either Rows("3:3").Select or
Rows(3).Select.

I tried both of those attached to a command button placed on a worksheet and
they ran okay. In the past I remember that a commandbutton's "take focus on
click" property being True was sometimes a problem but I found my code ran
whether it was true or false.

--
Jim
|
| Thank you, I will try that; I have access to the particular system after
| hours so it will be a while before I can try it.
|
| But I do wonder why it works as a macro when I run it using the shortcut
key
| I've set up. I ran it and tested it before I attached it ot the button so
I
| thought it would run; also, I developed the macro originally by using the
| "Record macro" feature so the syntax should have been correct.
|
| "Jim Rech" wrote:
|
| > Your code should be Rows(3).Select I think.
| >
| > --
| > Jim
| > | > | Excel 2007:
| > |
| > | I've written a macro which I can run with the shortcut key but when I
| > attach
| > | it to a button it gives me an error on the line:
Rows(3:3).Select
| > |
| > | Is there a property that has to be set for the button to make it run
the
| > | macro?
| > |
| > | I have been using Excell 2003 and hadn't used Excel 2007 until
somemone
| > new
| > | arrrived and the system they set up for her had the new version and I
| > don't
| > | have a manual for it.
| >
| >
| >
 
K

kim s

Quite right, I did type the code in rather than copy and paste as the system
giving me a problem is availbale only for short times, and in the macro it
was Rows("3:3").Select as you say; I was unaware of Rows(3).Select but I
could try that.

As I say I don't have access to the system in question very much so my
opportunity to try things our is limited but I will try Rows(3) to see if
that makes any difference.

Thanks for your help.
Kim
 
J

Jim Rech

If it was Rows("3:3").Select then I don't think Rows(3) will work any
better. You might note the exact error message...
 
Top