+ Reply to Thread
Results 1 to 34 of 34

Button Click on Spreadsheet commanded by Button Click on Userform

  1. #1
    Registered User
    Join Date
    04-03-2015
    Location
    Limerick, Ireland
    MS-Off Ver
    2010
    Posts
    31

    Button Click on Spreadsheet commanded by Button Click on Userform

    Hi Guys,

    So I have code within a button on a Spreadsheet(Production Assign). I want this code to run after a button is clicked on a Userform(Monitors Office Entry). The button on the userform inserts data into the spreadsheet, and the button on the spreadsheet makes calculations according to the inserted data and sends an email.

    I have tried this code within the MonitorsOfficeEntry_Click():
    Please Login or Register  to view this content.
    Any feedback on what I can do to make this work would be great. Thanks.

  2. #2
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Button Click on Spreadsheet commanded by Button Click on Userform

    It would be easier if you would just post the workbook that all of this is in. Remove any sensitive data and replace with a bit of dummy data.

    View Pic
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

  3. #3
    Registered User
    Join Date
    04-03-2015
    Location
    Limerick, Ireland
    MS-Off Ver
    2010
    Posts
    31

    Re: Button Click on Spreadsheet commanded by Button Click on Userform

    Cool, I have attached the file. What I would like to achieve is for the "Assign Batch Record" button on the "Monitors Office Entry" userform, to activate the "Send Email" button on the "Production Assign" spreadsheet.
    Likewise, the "Assign Batch Record" button on the "Production Office Entry" userform, to activate the "Send Email" button on the "QA Assign" spreadsheet.
    And,the "Assign Batch Record" button on the "QA Office Entry" userform, to activate the "Send Email" button on the "QP Assign" spreadsheet.

    Thank you in advance if you can find a solution.
    Attached Files Attached Files

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Button Click on Spreadsheet commanded by Button Click on Userform

    Why not just call the sub assigned to both worksheet buttons, SendEmail_Click, from the click event of the button on the userform?
    If posting code please use code tags, see here.

  5. #5
    Registered User
    Join Date
    04-03-2015
    Location
    Limerick, Ireland
    MS-Off Ver
    2010
    Posts
    31

    Re: Button Click on Spreadsheet commanded by Button Click on Userform

    I think that is what I tried to do. I inserted the code I have above in my first post into the click event on the userform, but I just keep getting an error when trying to run it

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Button Click on Spreadsheet commanded by Button Click on Userform

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

  7. #7
    Registered User
    Join Date
    04-03-2015
    Location
    Limerick, Ireland
    MS-Off Ver
    2010
    Posts
    31

    Re: Button Click on Spreadsheet commanded by Button Click on Userform

    Wow...and its as easy as that haha. Thanks very much Norie

  8. #8
    Registered User
    Join Date
    04-03-2015
    Location
    Limerick, Ireland
    MS-Off Ver
    2010
    Posts
    31

    Re: Button Click on Spreadsheet commanded by Button Click on Userform

    Norie, i have 3 separate spreadsheets, one button on each spreadsheet, I put my code in to each button and they all work perfect, then I go to my userforms (there are 3 userforms that interact with their appropriate spreadsheet) and I put in the code
    Please Login or Register  to view this content.
    But I receive compile error: Sub or Function not defined. Have you any idea why?

    Apologies for what could be silly questions, but I am a very very novice programmer trying to make a project work.

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Button Click on Spreadsheet commanded by Button Click on Userform

    Is this another macro/sub you are trying to run?

    Where is it located?

    Is it a Public or Private sub?

  10. #10
    Registered User
    Join Date
    04-03-2015
    Location
    Limerick, Ireland
    MS-Off Ver
    2010
    Posts
    31

    Re: Button Click on Spreadsheet commanded by Button Click on Userform

    I did not create a macro, I just created an ActiveX button and placed my code inside the view code section.
    This is on the spreadsheet. I click the button on the spreadsheet and it carries out my task.
    It says Private Sub.

    The user will not have access to the spreadsheets, this is why I want to activate the button from the userform.

  11. #11
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Button Click on Spreadsheet commanded by Button Click on Userform

    Remove Private.

  12. #12
    Registered User
    Join Date
    04-03-2015
    Location
    Limerick, Ireland
    MS-Off Ver
    2010
    Posts
    31

    Re: Button Click on Spreadsheet commanded by Button Click on Userform

    I have tried literally removing it and that did not work, is there another way I am supposed to take it off of private? Am I supposed to replace it with "Public"?

  13. #13
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Button Click on Spreadsheet commanded by Button Click on Userform

    Can you upload an example workbook?

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

  14. #14
    Registered User
    Join Date
    04-03-2015
    Location
    Limerick, Ireland
    MS-Off Ver
    2010
    Posts
    31

    Re: Button Click on Spreadsheet commanded by Button Click on Userform

    Cool. Any questions about it don't hesitate to ask.
    Attached Files Attached Files

  15. #15
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Button Click on Spreadsheet commanded by Button Click on Userform

    This will work.
    Please Login or Register  to view this content.
    However I don't think calling events of controls is a good idea.

    What I would do is move the code for the button to a separate sub in a standard module.

    You can then call that sub from anywhere else, including the original button that called it.

    Actually, you've basically already have that with the sub SendMail_Click.

  16. #16
    Registered User
    Join Date
    04-03-2015
    Location
    Limerick, Ireland
    MS-Off Ver
    2010
    Posts
    31

    Re: Button Click on Spreadsheet commanded by Button Click on Userform

    Ok so just to try get my head around that, What I should do is:
    Create Module 1, create Module 2, create Module 3.
    Put the exact same code I have in my CommandButton1_Click code into Module 1, and same for cmd2 and 3 with mod 2 and 3?
    And then use the code you posted above to call it? or do I make it call the module somehow?

  17. #17
    Registered User
    Join Date
    04-03-2015
    Location
    Limerick, Ireland
    MS-Off Ver
    2010
    Posts
    31

    Re: Button Click on Spreadsheet commanded by Button Click on Userform

    Ok just to try get my head around it, I should:
    Create Module 1, Module 2 and Module 3?
    Copy and paste the exact same code from the command buttons 1,2 and 3 into the respective modules?
    Use your code above then to make that work? Or is there a different way to the module maybe?

    Thanks for your help Norie.

  18. #18
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Button Click on Spreadsheet commanded by Button Click on Userform

    If you have common code that you want to call from various different places/buttons etc you should put it in a standard module.

    Then it can be called from anywhere in the workbook.

    There's no need for mutliple modules, the subs, given appropriate names, can all go in one module.

  19. #19
    Registered User
    Join Date
    04-03-2015
    Location
    Limerick, Ireland
    MS-Off Ver
    2010
    Posts
    31

    Re: Button Click on Spreadsheet commanded by Button Click on Userform

    It doesnt seem to be working for me yet anyway, I can get the userform button to carry out the code it is meant to, but it does not activate the button on the spreadsheet still.
    I have taken everything off private sub to just- Sub.

    I have it all in the one module now and all the iterate numbers changed appropriately.
    And just using the: "Call CommandButton1(2,3)_Click" code on each userform.
    Last edited by Quilie19; 04-06-2015 at 11:22 PM.

  20. #20
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Button Click on Spreadsheet commanded by Button Click on Userform

    Where does the 2,3 come into things?

    What is the code meant to do and where do you want to call it from?

  21. #21
    Registered User
    Join Date
    04-03-2015
    Location
    Limerick, Ireland
    MS-Off Ver
    2010
    Posts
    31

    Re: Button Click on Spreadsheet commanded by Button Click on Userform

    The 2,3 refers to CommandButton2_Click and CommandButton3_Click that are in the respective userform button_click code.
    I have Sub CommandButton1 , 2, and 3 all in the one module now.

    OK to explain what is happening:
    There are 3 Offices that will use this function on the userform; the Monitors Office Entry, Production Office Entry, and the QA Office Entry. Each of these 3 userforms has the same layout. Each userform interacts with a separate spreadsheet.
    On the userform, the user will complete the Textbox and Comboboxes, when they click the "Assign batch record button", the results from the userform go into the appropriate spreadsheet(depending what Entry userform the user is on) and preform a calculation, that in turn will choose a name from one of 3 tables.

    What the button on that spreadsheet then does, is send an email, move the name on that particular table down the list and a new name on top, and also paste the value from the Textbox value and the Chosen name from the table in another spreadsheet(again depending what spreadsheet the button is being clicked on, will decide what spreadsheet that data gets pasted to).

  22. #22
    Registered User
    Join Date
    04-03-2015
    Location
    Limerick, Ireland
    MS-Off Ver
    2010
    Posts
    31

    Re: Button Click on Spreadsheet commanded by Button Click on Userform

    I'm still having no luck calling a click on a spreadsheet button from a userform button click :'( why is this proving so difficult!

  23. #23
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Button Click on Spreadsheet commanded by Button Click on Userform

    Have you moved the code you want to be called from the various worksheet/userform buttons to a standard module with a suitably descriptive name?

  24. #24
    Registered User
    Join Date
    04-03-2015
    Location
    Limerick, Ireland
    MS-Off Ver
    2010
    Posts
    31

    Re: Button Click on Spreadsheet commanded by Button Click on Userform

    Do I put the Userform Button click code into the module with the Spreadsheet Button click code?

  25. #25
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Button Click on Spreadsheet commanded by Button Click on Userform

    Let's say you had code that sent an email in a sub called SendEmail and you wanted to call that from a button on a worksheet and a button on a useform.

    In a standard module you would have the sub SendMail.
    Please Login or Register  to view this content.
    You would now call the sub from the worksheet button, or userform button like this.
    Please Login or Register  to view this content.

  26. #26
    Registered User
    Join Date
    04-03-2015
    Location
    Limerick, Ireland
    MS-Off Ver
    2010
    Posts
    31

    Re: Button Click on Spreadsheet commanded by Button Click on Userform

    Was just looking at the difference between a standard and class module there, and maybe it is a class module I should be using as I want it to do 3 separate clicks on different sheets?

    I have tried the above...I even tried recording new macros on each spreadsheet for each click, and then tried to just call those macros from the userforms...but no no luck with that either.
    Haha this function of my program has me stressed as feck

  27. #27
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Button Click on Spreadsheet commanded by Button Click on Userform

    It's not a class module you need, it's a standard module.

    Can I just clarify one thing?

    The code you want to execute is exactly the same for both the button on the worksheet and the button on the userform?

  28. #28
    Registered User
    Join Date
    04-03-2015
    Location
    Limerick, Ireland
    MS-Off Ver
    2010
    Posts
    31

    Re: Button Click on Spreadsheet commanded by Button Click on Userform

    No not exactly the same.
    The bulk of the code is all the same for the calculations on the spreadsheet, but each button sends information from its spreadsheet to another spreadsheet.

    So, cmd btn1 does:
    Please Login or Register  to view this content.
    cmd btn2 does:
    Please Login or Register  to view this content.
    cmd btn3 does:
    Please Login or Register  to view this content.

  29. #29
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Button Click on Spreadsheet commanded by Button Click on Userform

    Is the only thing that changes the sheet the code runs on?

    Which sheet are C26, A1 and A26 on?

  30. #30
    Registered User
    Join Date
    04-03-2015
    Location
    Limerick, Ireland
    MS-Off Ver
    2010
    Posts
    31

    Re: Button Click on Spreadsheet commanded by Button Click on Userform

    Yes, each userform button interacts with a separate sheet.

    C26, A1 and A26 are all on the spreadsheet of which ever button is been pressed. Keep in mind each spreadsheet with the buttons I am trying to click are all the exact same, except in the code they copy the information from A1 and A26 to different sheets again.

  31. #31
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Button Click on Spreadsheet commanded by Button Click on Userform

    Do you mean C26, A1, A26 are on the worksheet the button is interacting with?

  32. #32
    Registered User
    Join Date
    04-03-2015
    Location
    Limerick, Ireland
    MS-Off Ver
    2010
    Posts
    31

    Re: Button Click on Spreadsheet commanded by Button Click on Userform

    Yes they are.
    And depending what user form is used(to click the button) will decide what worksheet is interacted with.

  33. #33
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Button Click on Spreadsheet commanded by Button Click on Userform

    Right, last question (I hope), Iteratex is the sub you want to call from the buttons?

  34. #34
    Registered User
    Join Date
    04-03-2015
    Location
    Limerick, Ireland
    MS-Off Ver
    2010
    Posts
    31

    Re: Button Click on Spreadsheet commanded by Button Click on Userform

    Well from the "Monitors Office Entry" userform button - "Assign Batch Record", I want to call the "Prod Assign" spreadsheet button- "Sub CommandButton1_Click()", and then when that button is clicked it will carry out the sub Iterate code. (This code decides which table out of 3 tables to choose, and then from what ever table is chosen it will take the name from the top of the table to assign the batch record to. And that is the information that is sent to the "Production Office" spreadsheet then- the name and the batch record number.)

    And the same then for the "Production Office Entry" userform and "QA Office Entry" userform, that also have "Assign Batch Record" buttons that will interact with "Sub CommandButton2_Click()" on "QA Assign" spreadsheet and "Sub CommandButton3_Click()" on "QP Assign" spreadsheets.

+ 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] click on a color button and after button click it will color entire row of cell you click
    By swade730 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-11-2014, 06:06 PM
  2. Error on userform remove button click
    By gsurge in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 10-11-2012, 08:45 AM
  3. [SOLVED] Disable ALL Buttons on Button Click in UserForm
    By Nu2Java in forum Excel General
    Replies: 2
    Last Post: 10-05-2012, 02:58 PM
  4. UserForm, update after command button click
    By ker9 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-01-2010, 01:05 PM
  5. Can you use CTRL+Enter to click a userform button
    By johncassell in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-11-2006, 09:23 AM

Tags for this Thread

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