+ Reply to Thread
Results 1 to 19 of 19

Userform data entry code

  1. #1
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Userform data entry code

    How can I change this code so that it won't run if the text box SerialNumber equals 'none'?

    Please Login or Register  to view this content.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Userform data entry code

    Hi

    A ssuming the TextBox is on the Equipment Data sheet perhaos

    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Re: Userform data entry code

    Im getting run-time error '438', Object doesn't support this property or method.
    The Text box SerialNumber is located on a Userform called NewItem, and the code is ran from a command button on that user form.
    Also to verify it should be preventing the code from running when the text in the text box says none (not blank).

  4. #4
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: Userform data entry code

    Would this work?

    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: Userform data entry code

    Here's an alternative if you want it to prevent from running and unload when the TextBox named SerialNumber is blank:

    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Userform data entry code

    Hi nitefox,

    I would check the textbox before trying to populate the EquipmentData sheet i.e.

    Please Login or Register  to view this content.
    HTH

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  7. #7
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Re: Userform data entry code

    The code just ran as normal. When I type in the word NONE, it should be stopping the code from running so it doesn't add the text box values to the worksheet. Currently when I type in the word NONE it is still adding it to the workbook.

  8. #8
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Re: Userform data entry code

    That last code came up with Compile Error: End if without block if.

  9. #9
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Userform data entry code

    Try this which incorporates your second requirement:

    Please Login or Register  to view this content.
    Robert
    Last edited by Trebor76; 12-20-2013 at 08:16 PM.

  10. #10
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Re: Userform data entry code

    It is still allowing the code to run when I type in none. I think you are misunderstanding me to believe I mean a blank text box, but I literally mean the word none is typed into the text box.
    Also I just realized I need to make a slight change, rather than doing nothing when the word NONE is typed into SerialNumber, it should instead enter the value of the text box ItemDescription into active cell -1,-1.

  11. #11
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Userform data entry code

    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Re: Userform data entry code

    Thank you mehmetcik, that stopped it from adding the data to the worksheet, however I would like it to then enter the value of the text box ItemDescription into active cell -1,-1, and close the Userform NewItem.

  13. #13
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Userform data entry code

    I literally mean the word none is typed into the text box
    No, I understood you as that what the code does

  14. #14
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Re: Userform data entry code

    Sorry Trebor i somehow missed your last post. Thank you that code worked, in that it prevented it from adding the text box values to the worksheet. I am also looking to perform the following (just when none is entered):
    Enter the value of the text box ItemDescription into active cell -1,-1, and close the Userform NewItem.
    In any other case (when none is not entered) it should run the original code.

  15. #15
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Userform data entry code

    No problem. As long as the activecell is not in column A the following code for the none value should work:

    Please Login or Register  to view this content.
    Robert

  16. #16
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Re: Userform data entry code

    When SerialNumber is equal to none it came up with run time error 438, Object doesn't support this property or method on this line:
    Please Login or Register  to view this content.
    The active cell is in the G column on the ReturnData page.

  17. #17
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Userform data entry code

    You're not giving us all the information needed to provide an answer!! You didn't say anything about returning any value to any other tab besides EquipmentData which in this case has caused the error as you cannot reference an activecell outside the activesheet.

    Try this work around, which besides column A will not work from within row 1:

    Please Login or Register  to view this content.
    Robert

  18. #18
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Re: Userform data entry code

    Thank you Trebor that did it. I apologized I didn't realized I had not specified the worksheet.

  19. #19
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Userform data entry code

    No problem - I'm glad we've been able to solve it for you.

    Thanks for marking the thread as solved and for adding to my reputation

    Robert

+ 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. Edit VBA Userform code to run if only 1 entry that matches criteria
    By ExcelFailure in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 07-24-2013, 05:25 AM
  2. [SOLVED] Userform multipage control exit events code execution not completed before next user entry
    By jane serky in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-10-2013, 04:39 AM
  3. Userform data entry
    By amekock in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-19-2011, 10:26 AM
  4. UserForm for data entry
    By jay11 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-15-2010, 03:30 PM
  5. userform data entry
    By john tempest in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-06-2006, 10:45 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