Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Errors when using command buttons

VBA How To

Errors when using command buttons

by  xlbo  Posted    (Edited  )
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
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top