I'm gonna talk about how to generate error messages for empty fields on a
form in Excel so I have a very basic change of employment so we
have of course we have the first name last name and then we have on what type
of change it is and so you have a drop-down list here new hire promotions
and termination okay so let's go to select new hire and now let's go look at
the code I've written here so I'm gonna right click on the sheet tab and I'm
gonna go to view code and so there you have my macro that I've written I say is
empty so the first one is if c3 which is the first name field
if c3 is empty then the message box will say enter given name and now if it's
empty then I want it to go almost to the end
so I go to nd which I've labeled down here which is just before the end sub ok
so if that one's not empty then you go to the next one and say is enter or
is if empty and there you have that's our field for e3 so the is empty
is what the command I'm using what works very well and once again you have a
message box and enter surname and then go to ende and then we have the two end
ifs for those ones and then so if they select if they select in here our
terminations then the comments are mandatory you need to have a reason why
you've let these people go and so enter your comments are required in
termination selecting and then end if and if and then ende okay so let us go
so we have absolutely nothing in here and so let's go run this so I'm gonna
press now normally you would use this in a situation where you're having a button
to save the file or possibly to email it but I have
videos on both of those so I'm not gonna go into how that procedure works so what
we're gonna do is we're gonna go f8 here to go through this and then it goes it's
checking to see if c3 is empty which is the first name field and it says enter
give a name so we say ok so now let's reset that so that one works so let's
put in Barney and then I'm gonna feel in the second field because we can kind of
guess that that's gonna that that's gonna work ok so let's go back to our
our code here and let's go reset this and we're gonna go at f8 so we go f8 and
so it goes all the way through because everything's filled out and a new higher
was selected and so now we go to the end of the stop until the sub works fine now
let's go back to here and let's go back to the other one
now the comments field how I did this is I merged and the merged and
centered this cell here which the cell is all named c9 and I'm using the is
empty now let's select termination here and let's see if the error message works
for the termination so let's go back to my code and so let's go the f8 through
here so everything works from checking all the names
now it says if termination is selected then then you have to do another check
if c9 which is our merged in the center field is empty then you do a message box
comments are required of termination is selected you say ok so that's a very
simple method of having error messages displayed
empty fields please subscribe