+ Reply to Thread
Results 1 to 4 of 4

IF data not complete, exit sub

  1. #1
    Forum Contributor
    Join Date
    08-23-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    139

    IF data not complete, exit sub

    Hello All,

    My database building macro is working fine, but the users are not filling in all the information that would make my database complete.
    I am trying to put some checking in at the start of the macro that would notify the user that they need to add more information in order for the entry to be made into the database.

    My first few attempts look like this:

    Please Login or Register  to view this content.
    As you can see, I'm trying to test if the count of cells with data in ColV is less than the cells filled in, in ColB. This is my way of determining that the user has not filled in the supplier name for each item that they are wishing to enter.

    At the moment, when i test the macro it does not exit sub when the condition i am trying to test for is met.

    It's probably worth noting that I will be testing for the not only ColV, but also F,G,H,K,L,W as well - if there is a way to do all of these checks in one statement then i'd accept that, even if it means that the error message is generic
    IF("helping me", "thanks", "need more detail?")

  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: IF data not complete, exit sub

    Hi,

    The way I always do this sanity checking to ensure that all data has been entered is to use a single named cell in Excel, call it "Check" if you like.

    Then for every item that needs to have been completed, in the Check Cell I put stuff like
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    The idea being that when all relevant cells and conditions have been met the Check cell will be zero. Then your macro can simply read the Check Cell and proceed accordingly.

    i.e.

    Please Login or Register  to view this content.
    You can build on this idea. For instance if say all of a column of values must be completed you can use say an =INDEX(MATCH()) pair of functions to find the first description which has not been included and read the result of that function into a message box tp tell the user which is the first item that has not been entered.

    I find this approach far easier that using VBA and it's much easier to create functions to test the stuff you're trying to trap.
    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
    08-23-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    139

    Re: IF data not complete, exit sub

    Thanks for such a quick response.

    I will absolutely use a checksum cell and get my VBA to look for that. I'm currently kicking myself for not thinking of that in the first place!

    Simple, yet elegant

  4. #4
    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: IF data not complete, exit sub

    Glad to have helped and thanks for the rep.

+ 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. Textbox exit event prevents to exit userform
    By smjjvh in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-21-2014, 06:08 AM
  2. Texbox exit event prevents userform exit
    By smjjvh in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-21-2014, 05:47 AM
  3. [SOLVED] Want to exit sub if range have no data
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-06-2014, 03:37 AM
  4. [SOLVED] MSGBOX with structured data - OK / EXIT
    By rz6657 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-28-2013, 01:23 PM
  5. [SOLVED] Compare two folder files - whether they exit or not and if exit then copy to another foler
    By sthiru in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-10-2012, 12:08 AM

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