+ Reply to Thread
Results 1 to 10 of 10

Basic Userform to populate sheet not working

  1. #1
    Registered User
    Join Date
    12-07-2016
    Location
    Oregon, USA
    MS-Off Ver
    2016
    Posts
    33

    Basic Userform to populate sheet not working

    Hello all! I'm trying to create a very basic userform for data entry. I have watched tons of tutorials and found several sets of code to do this but none of them seem to work in my project. Below is some code that I've tried and I keep getting a run-time error and I cannot figure out why. Thanks for any help. The attached sheet only has 1 combo box in the userform to simplify this and I will adjust the code as I add more controls. The error seems to point to the "Set nextrow" line.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Betsy Simpkins; 11-08-2018 at 04:32 PM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Basic Userform to populate sheet not working

    Your post does not comply with Rule 2 of our Forum Rules: Use code tags around code.

    Posting code between
    [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE]
    tags makes your code much easier to read and copy for testing, it also maintains VBA formatting and allows vertical scrolling so long code takes up less space in the post.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 6.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    12-07-2016
    Location
    Oregon, USA
    MS-Off Ver
    2016
    Posts
    33

    Re: Basic Userform to populate sheet not working

    Thank you for pointing out the new rule, my apologies. It's fixed now.

  4. #4
    Forum Contributor
    Join Date
    10-01-2018
    Location
    Virginia Beach, VA
    MS-Off Ver
    365
    Posts
    129

    Re: Basic Userform to populate sheet not working

    Hi Betsy!

    If I'm understanding your goal correctly, you simply want the selected value in the "Team" combobox to be entered into the first empty line below the "Team" column header on sheet 2 when the "Update" button is clicked, correct?


    If that's all you're after, there's a much simpler way to achieve it than the code you are currently using. Try this method instead:


    Please Login or Register  to view this content.
    In my example, I've added lines to print the column header value in each of the other columns as a text string, but you would simply replace the portions in quotes with the following:
    Please Login or Register  to view this content.
    Where "XXXX" is the name of each additional combobox you set up for the other columns.

    I've attached a revised version of your example workbook with my code above inserted on the "AddRecordButton_Click()" event, so you can see how it works by clicking "Add Record" instead of "Update". You should be able to tweak the code from there to fit your needs.

    If you were going to use my method to replace the relevant section of code you currently have on the Update button, it would look something like this:

    Please Login or Register  to view this content.

    The lines I noted as "not needed" should be deleted, unless your full project has another purpose for those functions. I also recommend getting in the habit of indenting each section of code like I have done, particularly your "if" statements, to make your code easier for others to read and work on.

    Let me know how that works for you! Happy coding!!!
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    10-01-2018
    Location
    Virginia Beach, VA
    MS-Off Ver
    365
    Posts
    129

    Re: Basic Userform to populate sheet not working

    Here, since I had it done anyway, I've attached my final version of your example file, with my code replacing your original code instead of being on the Add Record button... Hope this helps!
    Attached Files Attached Files

  6. #6
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Basic Userform to populate sheet not working

    This should do the job.
    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Basic Userform to populate sheet not working

    Quote Originally Posted by Betsy Simpkins View Post
    Thank you for pointing out the new rule, my apologies. It's fixed now.
    Thanks for your attention. It's not a new rule; it's always been a rule.

  8. #8
    Registered User
    Join Date
    12-07-2016
    Location
    Oregon, USA
    MS-Off Ver
    2016
    Posts
    33

    Re: Basic Userform to populate sheet not working

    YES! Thank you Arnold this is exactly what I needed. Appreciate the help!

  9. #9
    Registered User
    Join Date
    12-07-2016
    Location
    Oregon, USA
    MS-Off Ver
    2016
    Posts
    33

    Re: Basic Userform to populate sheet not working

    Thanks Bakerman2, this is super helpful as well!

  10. #10
    Forum Contributor
    Join Date
    10-01-2018
    Location
    Virginia Beach, VA
    MS-Off Ver
    365
    Posts
    129

    Re: Basic Userform to populate sheet not working

    Quote Originally Posted by Betsy Simpkins View Post
    YES! Thank you Arnold this is exactly what I needed. Appreciate the help!
    No problem, glad I could be on the giving end of the help instead of the receiving end like usual, LOL!

    Don't forget to mark the thread as "Solved" if you're good to go... and maybe throw a click on the "add reputation" button if you feel so inclined.

+ 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] Excel stops working with Userform Textbox populate
    By sintek in forum Excel Programming / VBA / Macros
    Replies: 52
    Last Post: 05-22-2018, 10:14 AM
  2. [SOLVED] VBA to populate range with textbox.value form UserForm keyboard input not working
    By sintek in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-07-2016, 03:12 AM
  3. Populate Excel Userform with Sheet names with double click to open the sheet ??
    By Shacker in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 05-08-2013, 03:54 PM
  4. Populate Excel Userform with Sheet names
    By PC in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-08-2013, 09:37 AM
  5. Populate a UserForm field with value from excel sheet
    By onmyway in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 12-07-2012, 04:54 AM
  6. populate userform combobox with sheet names
    By tapapad in forum Excel General
    Replies: 3
    Last Post: 11-14-2008, 03:10 AM
  7. [SOLVED] Populate sheet from userform
    By cityfc in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-15-2006, 06:25 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