+ Reply to Thread
Results 1 to 5 of 5

Creating a Command button and assigning code to it

  1. #1
    Registered User
    Join Date
    10-17-2013
    Location
    Orlando
    MS-Off Ver
    Excel 2007
    Posts
    3

    Creating a Command button and assigning code to it

    I'm working on a project for work and could really use some help...

    I have a command button that when clicked, a message box pops up and asks to enter a name ('userinput') for a new item. This name is then inserted into a specific cell.

    What I'm trying to do is to (within the same command button procedure), create/copy another command button. And then add some code to the new command button that will input the same 'userinput' name value in the cell everytime its clicked.

    Two main things I would like to achieve

    1) Being able to click on the first button multiple times to create buttons with different names (i.e. userinput1, userinput2, etc.)
    2) Each time a new command button is created, it types in the unique 'userinput' value into the cell and is also captioned with that same name

    Please bear with me, I've only been playing with VBA for about 2 weeks specifically for this project I have for work and what I've learned so far has come from Google lol. Thanks in advance!

    Here is the code that I'm using, not sure what makes sense in there, it certainly doesn't work. Please add/delete as you deem necessary....it's really a cluster$#^$

    Please Login or Register  to view this content.
    Last edited by neallp31; 10-25-2013 at 03:25 PM.

  2. #2
    Registered User
    Join Date
    10-17-2013
    Location
    Orlando
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Creating a Command button and assigning code to it

    Sorry, I forgot to add code tags before...

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Creating a Command button and assigning code to it

    Hello neallp31,

    Welcome to the Forum!

    Thanks for adding the code tags. I don't see in the code where a "cell" is mentioned. Can you provide an example of how it work?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Registered User
    Join Date
    10-17-2013
    Location
    Orlando
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Creating a Command button and assigning code to it

    Hi, Thanks for replying...

    Actually, the cell that where the 'userinput' goes into has been given a name "item" in this case

    So for example

    Please Login or Register  to view this content.
    If the user enters "Maserati" in the input box

    then maserati is typed in the cell labeled 'item' and in turn, will affect the results of other cells that it is linked to that aren't part of this macro.

    So essentially, what I'm trying to do... not sure if it can be done... is that every someone types in a value, like "Maserati".... Then not only does the "item" cell get updated, but a button is created with the name "maserati" on it and that created button has a code that will type "Maserati" into the "item" cell. And if another user types BMW, then another, unique button is created with functions relating to Bmw...

    Basically an infinite loop of buttons and input values

    Hope this helps explain what I'm trying to do... Any ideas on how to do this??

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Creating a Command button and assigning code to it

    Hello neallp31,

    If you have a workbook can post, I can give you an answer faster.


    How To Post Your Workbook
    1. At the bottom right of the Reply window, Click the button Go Advanced
    2. At the top of the Your Message Window, in the first row of icons, Click the Paperclip icon.
    3. Click the Add Files button at the top right in the dialog box. This displays the File Manager dialog.
    4. Click the Select Files button at the bottom middle of the dialog.
    5. In the new window Find the file you want to upload, select it, and Click Open.
    6. You will now be back in the File Manager dialog. Click the bottom Middle button Upload File.
    7. Wait until the file has completely uploaded before you exit the File Manager dialog.

    File Manger Picture

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Create a command button with code with a command button
    By jakara in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-29-2013, 01:28 PM
  2. Code for a master command button to change the backcolor of multiple command buttons?
    By panttherm5 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-16-2012, 10:11 PM
  3. [SOLVED] vba code, command bar, command bar button, one button works but not two
    By amazingg64 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-13-2012, 09:55 AM
  4. Assigning macros to a command button
    By Impartial Derivative in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-26-2011, 02:13 PM
  5. [SOLVED] Help in assigning a command button
    By Fybo in forum Excel General
    Replies: 1
    Last Post: 09-19-2005, 03:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1