+ Reply to Thread
Results 1 to 13 of 13

Cancel Data Entry if text box is blank

  1. #1
    Registered User
    Join Date
    06-08-2015
    Location
    Glasgow
    MS-Off Ver
    2010
    Posts
    21

    Cancel Data Entry if text box is blank

    I apologise if this is a repost but I have been searching for a while and cannot find a solution to my problem

    I have created a userform in which there is a combo box and several text boxes these boxes input data into corresponding cells depending on the option selected in the combo box

    the problem I have is that when a text box is blank the data is still input into the spreadsheet leaving that cell blank

    I wish to write into the code that if a text box is blank the data entry is cancelled, focus is set onto that box and an error box comes up
    I have included my code below to show what I have at the moment

    Please Login or Register  to view this content.
    Last edited by SeanBaird; 06-10-2015 at 03:07 AM.

  2. #2
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Cancel Data Entry if text box is blank

    where is your data entry code?
    Last edited by humdingaling; 06-10-2015 at 03:14 AM.
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Registered User
    Join Date
    06-08-2015
    Location
    Glasgow
    MS-Off Ver
    2010
    Posts
    21

    Re: Cancel Data Entry if text box is blank

    apologies this is my first forum post I joined specifically to get an answer to this problem, this is essentially the whole code and it works for my data entry needs it is just creating the error bounds for the text boxes I am having difficulty with
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    06-08-2015
    Location
    Glasgow
    MS-Off Ver
    2010
    Posts
    21

    Re: Cancel Data Entry if text box is blank

    I have posted the code below

  5. #5
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Cancel Data Entry if text box is blank

    first

    i suggest you set it to pre check textbox
    what your code does is write all the outputs then check textbox
    ie put the check for txtno at the start

    Secondly
    to your original question
    put this at the start of the code
    Please Login or Register  to view this content.
    thirdly
    may i suggest you use select/case instead of 12 If statements
    as essentially you are just setting the outputs for the 12 months i presume

  6. #6
    Registered User
    Join Date
    06-08-2015
    Location
    Glasgow
    MS-Off Ver
    2010
    Posts
    21

    Re: Cancel Data Entry if text box is blank

    yes, I have only began using macros and vbe this week so I don't know what a lot of the codes do, I understand my code might not be the most effective way of doing it but it has the desired effect. what would pre checking the text box do and how would this work ? also if I wanted to check all text boxes would I just repeat that code ?

  7. #7
    Registered User
    Join Date
    06-08-2015
    Location
    Glasgow
    MS-Off Ver
    2010
    Posts
    21

    Re: Cancel Data Entry if text box is blank

    also if I put that section of code in at the beginning it still inputs the data into the worksheet.

  8. #8
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Cancel Data Entry if text box is blank

    i'm only throwing suggestions at you which should make your life easier for coding in the future
    you don't have to take on board if you are not comfortable with it or just want to leave it as is

    pre-checking allows you check the condition of the text box prior doing the actual data entry
    Please Login or Register  to view this content.
    ^^what this code does is
    checks if txtno is blank...if it is has a popup message box and stops the code from continuing

  9. #9
    Registered User
    Join Date
    06-08-2015
    Location
    Glasgow
    MS-Off Ver
    2010
    Posts
    21

    Re: Cancel Data Entry if text box is blank

    yeah that's cool ive ordered a book as well, its not a very user friendly interface for newbies.

    I entered that code at the beginning so my full code is now as below, however it still seems to input the data into the cells just leaving the cell corresponding to txtNo as blank
    Please Login or Register  to view this content.

  10. #10
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Cancel Data Entry if text box is blank

    the code isnt what i posted
    you are missing the exit sub bit

    i made a quick mock up of what i think you have setup
    using your 12 if statements

    bear in mind this only checks if txtNO is blank
    none of the other textbox are checked
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    06-08-2015
    Location
    Glasgow
    MS-Off Ver
    2010
    Posts
    21

    Re: Cancel Data Entry if text box is blank

    apologies I missed the exit sub line, your solution actually works perfectly. Thank you very much for your help it is much appreciated saved me a lot of time banging my head against a wall trying to get it sorted

  12. #12
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Cancel Data Entry if text box is blank

    since i created it already

    should you want to learn more about the suggestions i posted
    i made the amendments i suggested on v2 button

    it checks all textboxs and combobox to make sure they are not empty as well
    Attached Files Attached Files

  13. #13
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Cancel Data Entry if text box is blank

    then once you have learnt that method
    version 3 the really clean and short method

    Please Login or Register  to view this content.
    i also made a subroutine to clear form which you can call from any of the buttons now
    if you want me to explain any of it just let me know
    Attached Files Attached Files

+ 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. Replies: 0
    Last Post: 02-04-2014, 12:36 AM
  2. [SOLVED] IF data on opened worksheet has blank data then cancel macro and move onto next part
    By jonathan.haynes in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-01-2013, 07:11 AM
  3. Replies: 2
    Last Post: 09-18-2008, 05:47 AM
  4. [SOLVED] data validation drop-down menu blank entry
    By crapit in forum Excel General
    Replies: 2
    Last Post: 12-14-2005, 09:25 AM
  5. [SOLVED] data entry to next blank TextBox
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-17-2005, 06:05 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