+ Reply to Thread
Results 1 to 8 of 8

Putting Code To A Button In Excel / VB

  1. #1
    Registered User
    Join Date
    02-26-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    11

    Putting Code To A Button In Excel / VB

    I have managed to find online, code to add the date into a cell depending on the properties of that cell which all works fine if I run the code from VB. Now I need to add this to a button command. I am sure this is simple to do but I cannot get it to work. I know how to create the button but I cannot adjust the code to make it work. My code is:

    Please Login or Register  to view this content.
    Any ideas would be gratefully received.

    Cheers

  2. #2
    Registered User
    Join Date
    04-14-2013
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    66

    Re: Putting Code To A Button In Excel / VB

    Go to the developer ribbon - controls - insert - then add a button anywhere you want. When the assign macros box shows up insert the macro you want to attach it to. It is that simple. Good Luck.






    -If you found this helpful, feel free to express thanks with the star in the bottom left.

  3. #3
    Registered User
    Join Date
    02-26-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Putting Code To A Button In Excel / VB

    Thanks for the quick response. I tried this and I get a 400 error message?

  4. #4
    Registered User
    Join Date
    04-14-2013
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    66

    Re: Putting Code To A Button In Excel / VB

    You getting the error when you press the button? If so it is most likely a problem with the code you have linked to the button.
    Last edited by RS15; 04-15-2013 at 05:41 PM.

  5. #5
    Registered User
    Join Date
    04-14-2013
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    66

    Re: Putting Code To A Button In Excel / VB

    What is your VBA code trying to do?

  6. #6
    Registered User
    Join Date
    02-26-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Putting Code To A Button In Excel / VB

    It adds the date into a cell if the cell value is Y and as I said it works fine in VB, it just wont work when I add it as a macro on the button.

  7. #7
    Registered User
    Join Date
    04-14-2013
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    66

    Re: Putting Code To A Button In Excel / VB

    VBA Button.xls

    I tested it out and it seems to work fine for me. Let me know if this works on your computer, otherwise it might be a problem with your settings.

    Also, I am not sure the exact purpose of you VBA code but you might want to add a space between the Y and date or maybe put the date in the adjacent cell.
    If you found this helpful, click the star

  8. #8
    Registered User
    Join Date
    02-26-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Putting Code To A Button In Excel / VB

    I know what I have done wrong now. The button I have created does not appear on the same sheet as the column that needs changing. Is there a way to associate the code to a certain sheet so I can have the button on a different one? Thanks again for all of your help by the way, I am very new to VB and am constantly making school boy errors.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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