+ Reply to Thread
Results 1 to 14 of 14

Combining 5 Macro Buttons into one

  1. #1
    Forum Contributor
    Join Date
    08-30-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    142

    Combining 5 Macro Buttons into one

    I currently have 5 buttons all with a Macro attached on a spreadsheet. I want to combine these into one button. This will make I a lot easy for the End User.

    Can I do this by just taking the 5 parts of vba and creating one piece of code.

    Sorry if this doesn't make sense new to VBA

    Thanks

    Ted

  2. #2
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Combining 5 Macro Buttons into one

    Yes you can.
    Please ensure you mark your thread as Solved once it is. Click here to see how.
    If a post helps, please don't forget to add to our reputation by clicking the star icon in the bottom left-hand corner of a post.

  3. #3
    Forum Contributor HerryMarkowitz's Avatar
    Join Date
    09-10-2012
    Location
    Europe
    MS-Off Ver
    Office 2021 - Win10
    Posts
    1,007

    Re: Combining 5 Macro Buttons into one

    You can use;
    Call method
    or
    Application.Run method.
    Check following link;
    http://www.excelforum.com/excel-prog...acro-name.html
    Sub DontForgetThese()
         If Your thread includes any code Then Please use code tags...
         If Your thread has been solved Then Please mark as solved...
         If Anybody has helped to you Then Please add reputation...
    End Sub

  4. #4
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Combining 5 Macro Buttons into one

    also, you can create another sub, that calls that calls the first 5 one by one e.g.pseudo code:

    Please Login or Register  to view this content.
    If you are pleased with a member's answer then use the Star icon to rate it.

  5. #5
    Forum Contributor
    Join Date
    08-30-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    142

    Re: Combining 5 Macro Buttons into one

    I have put the 5 pieces of code together, as below is this correct

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    08-30-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    142

    Re: Combining 5 Macro Buttons into one

    Sorry, but ive just been thinking this through I suppose given that all of the parts are specific to the active cell that is being selected I wont be able just select one cell or all of the cells as it just wont work. Could this issue be overcome

    Thanks again

    Ted

  7. #7
    Forum Contributor HerryMarkowitz's Avatar
    Join Date
    09-10-2012
    Location
    Europe
    MS-Off Ver
    Office 2021 - Win10
    Posts
    1,007

    Re: Combining 5 Macro Buttons into one

    Maybe...
    Please Login or Register  to view this content.

  8. #8
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Combining 5 Macro Buttons into one

    first of all, do you understand that first 3 macros will overwrite each other (either if it is the active cell or some other selection)...

    4 macro is actually doing what .Value = .Value has already done - converting formulas to values

    Finally the 5th macro will overwrite the first three...
    so the result of running these 5 macros one after another will be exactly the same as running just the last (5th) one.


    The idea to have them on different buttons is to insert different formula in different cells...
    I assume you would like to have them work on different cells actually, not the same selection

    @ Harry - It's bad coding practice to chain macros like this.
    If you want to run them one after another - just create separate macro that will run the other 5. However look back to start of my comment

  9. #9
    Forum Contributor
    Join Date
    08-30-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    142

    Re: Combining 5 Macro Buttons into one

    Buran, I realised exactly what you've said see my comment above. The process the users is doing is basically working across a spreadsheet and at this point each time they select a cell they would click on the appropriate button, but each button specifies the active cell is there anyway round doing this without having to select each cell as each action is basically looking up another part of the spreadsheet relative to the cell.

    Thanks again

  10. #10
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Combining 5 Macro Buttons into one

    Quote Originally Posted by Ted Dennis View Post
    given that all of the parts are specific to the active cell that is being selected I wont be able just select one cell or all of the cells as it just wont work
    Sorry for misunderstanding. I decided that you want to run it for the selection, not just the active cell (i.e. it's possible to have selected 10 cells, but active cell is always a single one within the selection).
    can you specify how the cells are related, e.g. if user select one cell (or more) then run macro 1, second macro runs on cell on the same row and 3 columns to the right, etc....?

  11. #11
    Forum Contributor
    Join Date
    08-30-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    142

    Re: Combining 5 Macro Buttons into one

    Hopefully this should make sense

    Button 1 - Is a vlookup bringing back a date from another worksheet that's why the this has to be an active cell as it s looking for a name that exists in this spreadsheet.
    Button 2 - is the same as above but is bring back a date
    Button 3 - as above
    Random Number is as it says generating a random number
    Button 4 - Is an If which decides an outcome dependant on the various details pulled through by previous buttons.

    As far as I understand (limited knowledge on the vba front) I need to have active cell as this is a lookup

    Any help would be great

    Thanks again

    Ted

  12. #12
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Combining 5 Macro Buttons into one

    I see what each macro is doing. however if you apply them on same cell one after another, final result will be the same as applying only macro 5. And you said you realised that too. So it makes sense to apply 5 macros with one click, but each macro on different target cell. my question was how you decide on each cell, relative to the first one. In other words if you run macro 1 on cell a1, which cell should be used for macro 2, etc.

  13. #13
    Forum Contributor
    Join Date
    08-30-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    142

    Re: Combining 5 Macro Buttons into one

    Quote Originally Posted by buran View Post
    I see what each macro is doing. however if you apply them on same cell one after another, final result will be the same as applying only macro 5. And you said you realised that too. So it makes sense to apply 5 macros with one click, but each macro on different target cell. my question was how you decide on each cell, relative to the first one. In other words if you run macro 1 on cell a1, which cell should be used for macro 2, etc.
    Macro 1 on A1, 2 on A2, 3 on a3 etc

    Hope that clarifies

    Thanks

  14. #14
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Combining 5 Macro Buttons into one

    What exactly are you trying to accomplish?

    It would make most sense to post a sample workbook to the forum.

+ 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. EXCEL taskbar buttons combining
    By Jonibenj in forum Excel General
    Replies: 3
    Last Post: 03-03-2015, 04:49 PM
  2. Macro buttons and Option buttons in same ark bugs?
    By Ugabuga in forum Excel General
    Replies: 0
    Last Post: 10-12-2014, 06:04 PM
  3. [SOLVED] Combining three command buttons into one
    By KK1234 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-25-2013, 05:07 AM
  4. Combining buttons and VBA to build matrix
    By hamudenben in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-01-2012, 02:03 PM
  5. [SOLVED] combining two short VBA scripts from two buttons
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-24-2006, 03:15 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