Hello,
I am attempting to run code in a user form that determines the difference between two dates (in two text boxes) and place that number in a third textbox. I am doing this for a large number of textboxes on the form. I want the code to check if either of the two date text boxes is blank, and if so, just move to the next line of code. I have "Then Exit Sub" in their now, which is not what I need as it stops the code and exits once it reaches an empty date textbox. I am just starting out with VBA so I'm not sure how to handle this. Any help is appreciated. Also, if there is an easy way to do this as a range of textboxes and shorten the code that would be amazing, but I'll take any help.
I am attempting to run code in a user form that determines the difference between two dates (in two text boxes) and place that number in a third textbox. I am doing this for a large number of textboxes on the form. I want the code to check if either of the two date text boxes is blank, and if so, just move to the next line of code. I have "Then Exit Sub" in their now, which is not what I need as it stops the code and exits once it reaches an empty date textbox. I am just starting out with VBA so I'm not sure how to handle this. Any help is appreciated. Also, if there is an easy way to do this as a range of textboxes and shorten the code that would be amazing, but I'll take any help.
Code:
If TextBox512.Value = "" Or TextBox497.Value = "" Then Exit Sub
TextBox573.Value = DateDiff("m", TextBox497, TextBox512) & " Mo"
If TextBox513.Value = "" Or TextBox498.Value = "" Then Exit Sub
TextBox574.Value = DateDiff("m", TextBox498, TextBox513) & " Mo"
If TextBox514.Value = "" Or TextBox499.Value = "" Then Exit Sub
TextBox575.Value = DateDiff("m", TextBox499, TextBox514) & " Mo"
If TextBox515.Value = "" Or TextBox500.Value = "" Then Exit Sub
TextBox576.Value = DateDiff("m", TextBox500, TextBox515) & " Mo"'........