+ Reply to Thread
Results 1 to 6 of 6

Adding several CommandButtons to same worksheet.

  1. #1
    Forum Contributor
    Join Date
    07-07-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    500

    Adding several CommandButtons to same worksheet.

    Greetings,
    I realize my question is VERY basic, but I am not able to figure it out.
    I want to have several Command Buttons on the same worksheet. Each Command Button will need to be "enabled" referencing different cells on a different worksheet.
    Ex:
    Command Button1 refers to Sheet1.Range ("BC7").
    Command Button2 refers to Sheet1.Range ("BC8").
    So forth.

    I am able to set-up CommandButton1 using Private Sub Worksheet_SelectionChange(ByVal Target As Range). However, when I add CommandButton2, it does not work.


    Please Login or Register  to view this content.
    Again, I know my question is basic, but I would appreciate any help given!
    Attached Images Attached Images
    Last edited by brentjohn; 04-08-2018 at 12:22 PM.

  2. #2
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Adding several CommandButtons to same worksheet.

    Moderation removed
    Last edited by Winon; 04-08-2018 at 12:43 PM. Reason: Code Tags are added
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  3. #3
    Forum Contributor
    Join Date
    07-07-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    500

    Re: Adding several CommandButtons to same worksheet.

    Winon,
    I am sorry for this error. I have followed your instruction (and will do for additional post).

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Adding several CommandButtons to same worksheet.

    Hi Brent,

    Code behind worksheets is supposed to be EVENT type code and only work on that individual sheet. If you want code to work across other sheets, you should put it in a Module. (See Insert Module)

    Read:

    http://www.cpearson.com/excel/Scope.aspx

    So the answer is you should have code in a module that is run when you click on those buttons. Each button could run a separate sub. If that doesn't work, then attach the full workbook and explain what you are trying to accomplish.

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  5. #5
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,483

    Re: Adding several CommandButtons to same worksheet.

    brentjohn,

    you can only have 1 Worksheet_SelectionChange event macro
    what you need to do is resolve the activation of your commandbuttons in the same selection event

    try the following code to replace yours
    Please Login or Register  to view this content.
    Cbool translates 0 as false and other values as True

  6. #6
    Forum Contributor
    Join Date
    07-07-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    500

    Re: Adding several CommandButtons to same worksheet.

    Roel,

    Thank you much!!! It works perfectly!!!

+ 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. Simple Class Module - Adding commandbuttons at runtime - Will not work
    By UpSkill in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-11-2013, 04:07 AM
  2. [SOLVED] Sorting CommandButtons
    By ikkuh in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-08-2013, 02:07 AM
  3. Different behaviour of CommandButtons
    By Kropi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-13-2012, 12:18 PM
  4. Adding multiple CommandButtons crashes Excel
    By drobles in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-10-2009, 11:00 AM
  5. How to copy commandbuttons
    By leonidas in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-25-2006, 10:10 AM
  6. Help to loop Commandbuttons vertically
    By davidm in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 01-29-2006, 08:10 PM
  7. [SOLVED] CommandButtons
    By Mats Samson in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-17-2006, 10:20 AM

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