+ Reply to Thread
Results 1 to 5 of 5

Execute code from auto generated buttons in a userform

  1. #1
    Registered User
    Join Date
    04-26-2008
    Posts
    11

    Execute code from auto generated buttons in a userform

    I soon don't have any hair left, so please help me out...

    I have 3 Regions with a number (different between regions) of companies. Via a userform i would like the user to state how many employees each company holds and save this information back to the spreadsheet.

    The attached file descibes my problem.

    1. Via a ComboBox Region A, B or C is choosen.

    2. By clicking the Indata-button the userform isshown. Since each region have different number of companies (cells F33:G54), the userform will have different number of Labels and TextBoxes depending on which region that is choosen.

    When the userform initiates, cells C15:C17, are used to decide what information will be shown in the userform. The Cancel-button and Save-button are also created when the userform initiates.

    By filling in number of employees and clicking the Save-button, the number of employees should be written to cell H34:H54.

    By clicking the Cancel-button, the userform should just be unloaded.


    I can not get this to work!

    1. How do I get the Cancel-button and Save-button to work? I can not get them to execute any code.
    2. How do I get the information in the textboxes (number of employees) to be written into the worksheet.

    Any ideas on how to solve this are more then wellcome!
    /Fredrik
    Attached Files Attached Files
    Last edited by Tellus; 08-27-2008 at 07:19 AM.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436
    Rather than add those 2 button via code do it at design stage. Code against the events as normal.
    Then when Initialising the userform re-position the 2 buttons.

    You could set the ControlSource property of the textbox, although this does not allow for the Cancelling of changed values.

    So maybe better to load the textbox as you create it. And code in the OK click event would loop through the controls you added and output the text to the appropriate cell.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    04-26-2008
    Posts
    11
    Re-positioning the buttons was just so clever. Why make things complicated? Thanks a lot!

    The problem with transfering data from the text boxes still remain though.

    When adding textboxes in design-mode I can refer to them in a way like this:

    Please Login or Register  to view this content.
    Since the text boxes are created at userform-initiation (Employees1...Employeesn), I can not refer to them when clicking the Save-button,

    In the userform initiation I have this code:
    Please Login or Register  to view this content.
    Any thoughts on how to refer to the textboxes?

    /Fred

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436
    Use something like this.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    04-26-2008
    Posts
    11
    Thanks Andy!

    Finaly it's working and my day is saved!

+ 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. Adding code to a form on the fly...
    By Ara in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-01-2007, 03:47 PM
  2. To execute code before XL loads.
    By Ricky1947 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-31-2007, 03:27 PM
  3. Removing command buttons using code
    By chalie1105 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-30-2006, 02:25 PM
  4. Muultiple userform 'reset' code question
    By peter.thompson in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 10-21-2006, 08:23 PM
  5. UserForm Code Question/Help
    By peter.thompson in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-14-2006, 02:29 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