Excel VBA - Make multiple fields required based on value of another field -
i've created request form in excel vb uses submit button generate email in outlook based on values entered form.
everything works fine. however, users fail complete necessary fields before submitting request.
i need sure user completes required fields when specific value entered cell d7 before submit request
here lost...i've tried approaching 2 different ways.
hopefully can me this!
approach 1:
when submit button pressed...
button_click() if range("d7").value = "special request" 'make cells b6, b7, b8, b9, d14 mandatory in order generate email on error resume next if thisworkbook.worksheets("request").range _ ("b6, b7, b8, b9, d14 ") nothing msgbox ("please confirm required fields have been completed!") 'do not generate email
approach 2:
when submit button pressed...
button_click() 'if value of cell d7 other "special feature", 'execute code normal generate email 'else, check empty fields in required cells ("b6, b7, b8, b9, d14 ") 'if required cells empty, display message , not generate email msgbox ("please confirm required fields have been completed!") 'if d7 = "special feature" , no required fields missing, 'continue executing code generate email
here's 1 way go it:
sub test() if range("d7").value = "special request" , _ range("b6").value = "" or _ range("b7").value = "" or _ range("b8").value = "" or _ range("b9").value = "" or _ range("d14").value = "" msgbox ("please confirm required fields have been completed!") exit sub else ' whatever method you're using generate email goes here end if end sub
here way using counta:
sub test2() if range("d7").value = "special request" , _ application.worksheetfunction.counta(range("b6:b9"), range("d14")) < 5 msgbox ("please confirm required fields have been completed!") exit sub else ' whatever method you're using generate email goes here end if end sub
Comments
Post a Comment