+ Reply to Thread
Results 1 to 8 of 8

VBA for Option Button on Userform to send data to Multiple Spreadsheets

  1. #1
    Registered User
    Join Date
    01-28-2013
    Location
    St. Charles, Ilinois, USA
    MS-Off Ver
    Excel 2010
    Posts
    4

    VBA for Option Button on Userform to send data to Multiple Spreadsheets

    Hello all-

    I have a rather large userform where I first select a worksheet for data through a list of option buttons and then enter the data on a different page in the same userform. I have been successful in getting data from the data entry fields to populate on the selected worksheet from the first set of radio buttons, but in my data entry section, my radio button (OptionButton1 -- at the bottom of the code) only populates on my master rather on the selected worksheet. It seems to ignore (or not account for) the previous radio button's selection for which worksheet to use for the userform's entry.

    Thank for any help in advance! My code:


    Please Login or Register  to view this content.
    Last edited by rcfrench; 03-15-2013 at 03:58 PM. Reason: Added code tags, as per forum rules. Don't forget!

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA for Option Button on Userform to send data to Multiple Spreadsheets

    Maybe this so you stop running all those IFs once you find the selected RadioButton:
    Please Login or Register  to view this content.

    Once one of these IFs is true, the ws will be set and all the rest skipped.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    01-28-2013
    Location
    St. Charles, Ilinois, USA
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: VBA for Option Button on Userform to send data to Multiple Spreadsheets

    Thank you JBeaucaire. I assume this makes my code more efficient, however, the "Yes" from optionbutton1 is still placed on the MASTER sheet rather than on the worksheet selected by the option buttons in the long If/ ElseIf. Is there a way to communicate to the Userform VBA for optionbutton1 that the "Yes" should be only be on the worksheet selected by first set of option buttons in the long If/ ElseIf?

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA for Option Button on Userform to send data to Multiple Spreadsheets

    You referring to this?:
    Please Login or Register  to view this content.

    If you want that "Yes" to go to the sheet where the radio button selected a specific sheet, then you'll need to add the same looping "check"

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    01-28-2013
    Location
    St. Charles, Ilinois, USA
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: VBA for Option Button on Userform to send data to Multiple Spreadsheets

    Thanks this works great. Data entered on the userform goes to the correct worksheet. I am stumped though on how to get it to enter data in the next available row for optionbutton1. I tried to use the same logic for option buttons for selecting the page however this just returned a Error91.

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA for Option Button on Userform to send data to Multiple Spreadsheets

    You'll have to explain that, or show your failed coding attempts.

  7. #7
    Registered User
    Join Date
    01-28-2013
    Location
    St. Charles, Ilinois, USA
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: VBA for Option Button on Userform to send data to Multiple Spreadsheets

    I was able to figure it out. You have been most helpful and again thank you. As a final question, would you have a suggestion on how I can speed up the code with the IF/ ElseIfs?

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA for Option Button on Userform to send data to Multiple Spreadsheets

    Those aren't particularly slow... and they abort as soon as ONE of them executes a TRUE result.

    You might use ScreenUpdating = False near the top of your macro, and ScreenUpdating = True right before you end the Sub.

    If that takes care of your original query, please select Thread Tools from the menu above and mark the thread as solved. Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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