+ Reply to Thread
Results 1 to 7 of 7

Assign 4 macros to a single button depending on a value of another cell

  1. #1
    Registered User
    Join Date
    11-10-2014
    Location
    Bucharest
    MS-Off Ver
    2013
    Posts
    6

    Thumbs up Assign 4 macros to a single button depending on a value of another cell

    Hello,
    I need some guidance on creating my doc.

    As a short introduction:
    I have 2 sheets: Sheet1 and Sheet2.
    On sheet 1 cell 2B I have a dorpdown List with values from Sheet2 A2:A5. The options in the dropdown list are called 1,2,3,4.
    On Sheet 1 I have a button that has a macro assigned to copy cells from Sheet 2 underneath it.

    For now I have assigned macro 1 for this button.

    I have 4 macros created for each Cell value on cell 2B (1,2,3,4) in order to copy the certain Cells from Sheet2.
    How do I make the button to perform macro1 if cell b2 has value 1, macro 2 if cell b2 has value 2, macro 3 if cell b2 has value 3 and macro 4 if cell B2 has value 4?

    Below is the code with all the 4 macros:

    Please Login or Register  to view this content.
    I have also attached the document.

    Thank you!hideunhide cells project.xlsm
    Last edited by detrimental; 11-10-2014 at 07:41 AM. Reason: added code tags

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,186

    Re: Assign 4 macros to a single button depending on a value of another cell

    Hi, detrimental,

    please have a look at Forum Rule#3 to understand why you are asked to apply code-tags to your procedure.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    11-10-2014
    Location
    Bucharest
    MS-Off Ver
    2013
    Posts
    6

    Re: Assign 4 macros to a single button depending on a value of another cell

    Hello,
    I have added code tags.
    Thanks.

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,186

    Re: Assign 4 macros to a single button depending on a value of another cell

    Hi, detrimental,

    I have reduced the code to use an event behind Sheet1 monitoring Range B2 and work accodingly.

    Code goes behind the Sheet, right-click on worksheet Tab and choose View Code, paste code into the code window:
    Please Login or Register  to view this content.
    Ciao,
    Holger

  5. #5
    Registered User
    Join Date
    11-10-2014
    Location
    Bucharest
    MS-Off Ver
    2013
    Posts
    6

    Re: Assign 4 macros to a single button depending on a value of another cell

    Magic!

    It works now and it copies the values from sheet 2. I still have a question though. Is it possible to copy also the background color (the exact cell formatting from sheet 2) and not just the values?

    Many thanks.

  6. #6
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,186

    Re: Assign 4 macros to a single button depending on a value of another cell

    Hi, detrimental,

    use the Copy command like this:
    Please Login or Register  to view this content.
    Ciao,
    Holger

  7. #7
    Registered User
    Join Date
    11-10-2014
    Location
    Bucharest
    MS-Off Ver
    2013
    Posts
    6

    Re: Assign 4 macros to a single button depending on a value of another cell

    Thanks for the promptitude! Solved

+ 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. [SOLVED] assign two macros to the same button
    By iwannabakat in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-10-2014, 04:09 PM
  2. Create Multiple Command Button Assign to different macros
    By Konexcelmath in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-14-2013, 05:40 AM
  3. Assign two macros to a command button, but only one can automatically run!!
    By paulyb in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-14-2012, 01:06 PM
  4. Need to run macros depending on msgbox button clicked
    By rosshkerr in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-01-2012, 06:07 AM
  5. Replies: 6
    Last Post: 12-23-2009, 02:28 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