+ Reply to Thread
Results 1 to 10 of 10

VBA to check if certain fields have been completed before proceeding with event

  1. #1
    Registered User
    Join Date
    11-09-2016
    Location
    UK
    MS-Off Ver
    365
    Posts
    85

    VBA to check if certain fields have been completed before proceeding with event

    I have a user form containing some "mandatory fields", I have some current code which saves the file and attaches it to an email, before doing that it checks to see if the mandatory fields have been completed and if not it turns the questions red and pops up a msgbox advising the user to complete the fields

    current code:

    Please Login or Register  to view this content.
    followed by the rest of the code to save/attach to email etc


    To develop this further, I've been asked to add in some additional mandatory fields but these are based on dynamic sections - ie we have a section which asks for the number of people involved, if the user selects 1 person, 1 set of additional fields becomes visible asking for info such as name, address etc, if they select 2 then 2 sections come up etc (up to 3)

    There are 4 sections like this, each with the option to add details for up to 3 people.

    what I've been asked for is to give each of these sections mandatory fields

    so if 1 person is added then they must have a title and surname filled out, if 2 people are added then both additional sections must have title and surname, and so on

    I can make this work but not without adding tonnes of lines of code which I fear will impact performance

    my thoughts were along the lines of:

    Please Login or Register  to view this content.
    adding the rules for each statement after the else..

    but I'm relatively new to VBA and sure this is long winded

    is there an efficient way to make this work?

    many thanks
    Last edited by Maleficent; 08-26-2019 at 10:00 AM.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2507 (Windows 11 Home 24H2 64-bit)
    Posts
    91,887

    Re: Nested IF Statements

    Administrative Note:

    We would very much like to help you with your query, however the thread title does not really convey what your request is about.

    Please take a moment to amend your thread title. Make sure that the title properly explains your request. Your title should be explicit and not be generic (this includes function names used without an indication of what you are trying to achieve).

    Please see Forum Rule #1 about proper thread titles and adjust accordingly. To edit the thread title, open the original post to edit and then click on Go Advanced (bottom right) to access the area where you can edit your title.

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,879

    Re: VBA to check if certain fields have been completed before proceeding with event

    Edit:
    Whoops,
    I started writing before Mod request.
    So I delete my answer :-(
    Best Regards,

    Kaper

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,879

    Re: VBA to check if certain fields have been completed before proceeding with event

    I hope the new (edited 4pm) thread title is acceptable, so:


    I'd try such construction:
    Please Login or Register  to view this content.
    Or (if it's always E(n) =1 and D(n-3)<=-1) something like:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    11-09-2016
    Location
    UK
    MS-Off Ver
    365
    Posts
    85

    Re: VBA to check if certain fields have been completed before proceeding with event

    Thanks Kaper, I have updated the title as requested!

  6. #6
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,879

    Re: VBA to check if certain fields have been completed before proceeding with event

    I've noted this (some lag in forum updating :-))
    so the code is re-published in: https://www.excelforum.com/excel-pro...ml#post5183411

  7. #7
    Registered User
    Join Date
    11-09-2016
    Location
    UK
    MS-Off Ver
    365
    Posts
    85

    Re: VBA to check if certain fields have been completed before proceeding with event

    Thanks Kaper

    I need to test several conditions so..

    section 1 - if 1 person, make 2 fields mandatory, if 2 people make 4 fields mandatory, if 3 people make 6 fields mandatory
    section 2 - as above
    etc for 4 sections

    I don't think I can use offset as the three subsections are checked against the same section heading

    so to try and simplify...

    if A1 = 1 then A3 & A4 are mandatory
    if A1 = 2 then A3, A4, A10 & A11 are mandatory
    if A1 = 3 then A3, A4, A10, A11, A17 & A18 are mandatory

    If A30 = 1 then A33 & A34 are mandatory
    etc etc (these cell refs are made up, just to give an idea)

    I hope this makes sense!

  8. #8
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,879

    Re: VBA to check if certain fields have been completed before proceeding with event

    Then the first code is probably better.
    Moreover, as you want o check several options, I think SELECT CASE instruction would suit better than simple IF

  9. #9
    Registered User
    Join Date
    11-09-2016
    Location
    UK
    MS-Off Ver
    365
    Posts
    85

    Re: VBA to check if certain fields have been completed before proceeding with event

    Thanks Kaper, I'm not familiar with Select Case - can you elaborate? thanks again!

  10. #10
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,879

    Re: VBA to check if certain fields have been completed before proceeding with event

    See for instance here: https://trumpexcel.com/vba-select-case/ (or other searches with "select case vba tutorial" keywords) how to use one SELECT CASE instead of a set of IF instructions

+ 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. Formula with nested IF statements & AND statements
    By Hollywood44 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-11-2018, 03:38 PM
  2. [SOLVED] Nested if statements containing multiple and statements
    By John M. in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 06-22-2014, 11:48 PM
  3. questions with if statements and nested if statements
    By Pat Excel in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 02-03-2013, 01:41 PM
  4. Nested if statements with AND and OR statements
    By joeljoel in forum Excel General
    Replies: 4
    Last Post: 08-08-2011, 12:57 PM
  5. Multiple nested IF statements and AND statements
    By TonyGetz in forum Excel General
    Replies: 2
    Last Post: 12-14-2010, 03:07 AM
  6. Nested If statements / logic statements
    By Brainless_09 in forum Excel General
    Replies: 3
    Last Post: 06-17-2009, 02:59 PM
  7. Replies: 12
    Last Post: 05-15-2009, 08:38 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