PC Review


Reply
Thread Tools Rate Thread

command button not working

 
 
Miree
Guest
Posts: n/a
 
      17th Sep 2008
I have a code, which works when i select run but i can not connect it to a
command button, I can get the code to work if i paste in to the work book(but
not the command button) but can not get it to work in the worksheet where
command button is.

Sub AutoNumber()
' AutoNumber Macro
Sheets("Formulations").Select
i = Range("A2") + 1
Sheets("Formulation").Select
Range("E17:E18") = i
End Sub

 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      17th Sep 2008
The simpliest way is to go into Desiign Mode and double click the Control
button. It will create the macro where yo can place you code. to enter
Design Mode

1) Worksheet Menu View - Toolbars - Control Toolbox
2) Press Triangle ICON whic is a toggle button to either Enter or Exit
Design Mode
3) Double click on Your control Button which wil bring you into VBA where
the new macro is created. Past your code into the macro
4) Go back to worksheet and Press Desgin Mode ICON (triangle) to Exit Design
Mode
5) Your control buttonMacro should now operate properly.

"Miree" wrote:

> I have a code, which works when i select run but i can not connect it to a
> command button, I can get the code to work if i paste in to the work book(but
> not the command button) but can not get it to work in the worksheet where
> command button is.
>
> Sub AutoNumber()
> ' AutoNumber Macro
> Sheets("Formulations").Select
> i = Range("A2") + 1
> Sheets("Formulation").Select
> Range("E17:E18") = i
> End Sub
>

 
Reply With Quote
 
paul.robinson@it-tallaght.ie
Guest
Posts: n/a
 
      17th Sep 2008
Hi
Get your button from the Forms Toolbar, not the Controls Toolbox. For
a Forms Toolbar button, you can right click it and assign your macro.
Your macro should be in a General code module, not the worksheet
module. To create a general module, go into the visual basic editor
and do Insert, Module. Paste your AutoNumber macro into there.

Your code probably does not work because your button is from the
Controls Toolbox. The macro attached here is a button_click event
macro which will go into a specific worksheet code module. All a bit
more complicated than you want.

regards
Paul

On Sep 17, 2:59*pm, Miree <Mi...@discussions.microsoft.com> wrote:
> I have a code, which works when i select run but i can not connect it to a
> command button, I can get the code to work if i paste in to the work book(but
> not the command button) but can not get it to work in the worksheet where
> command button is.
>
> Sub AutoNumber()
> ' AutoNumber Macro
> * * Sheets("Formulations").Select
> * * i = Range("A2") + 1
> * * Sheets("Formulation").Select
> * * Range("E17:E18") = i
> End Sub


 
Reply With Quote
 
Miree
Guest
Posts: n/a
 
      18th Sep 2008
Thank you Paul worked perfectly.

"Miree" wrote:

> I have a code, which works when i select run but i can not connect it to a
> command button, I can get the code to work if i paste in to the work book(but
> not the command button) but can not get it to work in the worksheet where
> command button is.
>
> Sub AutoNumber()
> ' AutoNumber Macro
> Sheets("Formulations").Select
> i = Range("A2") + 1
> Sheets("Formulation").Select
> Range("E17:E18") = i
> End Sub
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Command Button not working Twb Microsoft Access Forms 1 11th Feb 2010 02:03 PM
Command button not working! Cesar Urquidi Microsoft Access 3 8th Sep 2008 02:33 PM
Command button not working! Cesar Urquidi Microsoft Access Forms 1 5th Sep 2008 12:40 AM
Please Help! Command Button not working! =?Utf-8?B?QS4gU21hcnQ=?= Microsoft Access Form Coding 0 7th Oct 2005 08:56 AM
command button isn't working Nydia Microsoft Excel New Users 1 29th Apr 2005 10:31 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:48 PM.