Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-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!

*Tek-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

VBA Visual Basic for Applications (Microsoft) FAQ

VBA How To

Errors when using command buttons by xlbo
Posted: 20 May 03

This FAQ refers to CONTROLS toolbox command buttons which have far more properties than the old FORMS collection buttons. More will appear here but this is for starters as IMO, it is the most common error associated with commandbuttons.

1: I get a "1004" or "'9 subscript out of range" error when trying to run code from a button (ie the click event) BUT the code runs fine when run through the VBE / debug window

This is caused 99 times out of 100 by not setting the "TakeFocusOnClick" property of the command button to false. Many actions on ranges / sheets need the object to have the focus. Unless this property is changed, the focus goes straight to the command button and the code errors with either a "1004" or "'9 Subscript" error

The steps need to resolve this are:

1. Make sure you are in "design mode" (little blue set square)
2. Right click on the button
3. Choose "properties"
4. Select the "Take Focus On Click" property and change to FALSE
5. exit properties

Back to VBA Visual Basic for Applications (Microsoft) FAQ Index
Back to VBA Visual Basic for Applications (Microsoft) Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close