excel - VBA: subroutine with if statement and returning true or false? -



excel - VBA: subroutine with if statement and returning true or false? -

solved!

i have validate cells not empty, want create subroutine , pass variables need checked.

this came with:

sub errormessage(errmsg string, errrange string) if range(errrange) = "" msgbox errmsg, , "error:" range(errrange).activate 'this looking :doh:, 'end' line terminates everything.. end end sub

now when phone call button, actuall end sub of button?

i.e.

private sub commandbutton1_click() phone call errormessage("name missing", "d4") 'this function shouldn't called if there msgbox displayed above phone call sendemail end sub

how can create happen?

edit:

ok how sovled it, reason i'm trying avoid tons of lines of code in buttonclick sub, thoughts??

keep in mind thing has check 25 questions blanks before executing sendemail sub....

private sub commandbutton1_click() phone call validateentry("client name missing.", "d4") phone call validateentry("# not complete.", "d5") phone call validateentry("address same cv?", "d6") phone call validateentry("number missing.", "d8") phone call validateentry("type missing.", "d9") phone call validateentry("q1 requires yes or no.", "e19") phone call validateentry("q2 requires yes or no.", "e21") phone call validateentry("q3 requires yes or no.", "e23") phone call validateentry("q4 requires yes or no.", "e25") phone call validateentry("q5 requires date.", "d28") phone call validateentry("q6 requires yes or no.", "e30") phone call validateentry("q7 requires yes or no.", "e32") msgbox "passed" 'sendemail end sub sub validateentry(errmsg string, errrange string) if range(errrange) = "" msgbox errmsg, , "error:" range(errrange).activate end end if end sub

so, in example, you're looking "passed" notification sent when there info in cell d4, right?

this should work:

private function errormessage(errmsg string, errrange string) boolean errormessage = false if len(trim(range(errrange))) = 0 msgbox errmsg, , "error:" range(errrange).activate errormessage = true end if end function public sub commandbutton1_click() if errormessage("name missing", "d4") = false msgbox "passed" end if end sub

alternatively, can handle msgbox notifications within function, grouping similar logic together, , maintain button click event sub clean:

private function errormessage(errmsg string, errrange string) if len(trim(range(errrange))) = 0 msgbox errmsg, , "error:" range(errrange).activate else msgbox "passed" end if end function public sub commandbutton1_click() phone call errormessage("name missing", "d4") end sub

excel vba excel-vba subroutine

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -