+ Reply to Thread
Results 1 to 4 of 4

where to write the macro for a button.

  1. #1
    Registered User
    Join Date
    03-29-2011
    Location
    Molde, Norway
    MS-Off Ver
    Excel 2010
    Posts
    22

    where to write the macro for a button.

    I want to make a button in my excel sheet, and i write the macro in the microsoft excel objects, Sheet1, where the button is. That doesnt work, but if i write it in Module1, it works.

    Why doesnt it work when written in Sheet1. I know this is a very fundamental question which i propably should have been able to find an answer to, but i have now tried, and cant find that information. I'm sorry.

    I want several buttons in my "sheet1", and to me it makes sense that i should write the macros for all the buttons which is placed in sheet1, in the corresponding microsoft excel objects.

    As you may have figured out, i'm not completely familiar with the different purposes of excel objects and modules.

    I have done some VBA coding before, but thats a long time ago now, and i need help to get started.

    Thanks

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,438

    Re: where to write the macro for a button.

    Assume you are using Form controls, rather than ActiveX, and are trying to assign a macro.

    Generally the button code would be stored in a standard code module.
    But if you want to place the code in the sheet object then you can. You just need to assign the macro to the local routine.

    Sheet1.Button2_Click
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    03-29-2011
    Location
    Molde, Norway
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: where to write the macro for a button.

    That was it.

    Thanks.

    I had ! instead of ., and i guess thats another kind of reference.

  4. #4
    Valued Forum Contributor jwright650's Avatar
    Join Date
    12-10-2010
    Location
    Va, USA
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    606

    Re: where to write the macro for a button.

    Something that Excel does is a help to me.....

    ie.Command button on a sheet...while in Design mode, right-click the object(cmdButton) and choose "view code"....you can add the code for the button there.

    ie.Active X controls for a UserForm, when you add the controls to the UserForm, you can double-click the control and it will open the editor window so you can add the code for that control.
    Life is like a roll of toilet paper. The closer it gets to the end, the faster it goes.
    John Wright

+ 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