I'm trying to create a macro to validate if a non continuous range is filled out and then delete empty rows after the last row that contains values.
In the above image, Columns A, D, G, H, I are mandatory fields. If one contains a value the rest of the mandatory fields must also contain a value. The green highlighted cells are an example of inputs that would pass validation, whereas the yellow would need to fail as the value in A and G are not filled out.
I've tried the below:
Sub Validate()
Dim Cell As Range
For Each Cell In Union(Range("A2:A3"), Range("D2:D3"), Range("G2:G3"), Range("H2:H3"), Range("I2:I3"))
If IsEmpty(Cell) Then
MsgBox ("Error: All mandatory fields must be filled out") 'actions To Do If True
End If
Next
End Sub
The problem is that the number of rows will be different every time a user inputs information and once they are done they will leave the rest of the rows blank. I'm not too sure how to proceed as I'm pretty new to VBA and coding in general. I'm hoping a loop of some sort that checks for these mandatory fields and stops once it encounters an empty row will do the trick, but then again I really don't know much about coding.
I found VBA to delete empty rows, shown below, and would like to have that run after the validation completes.
Unfortunately the code sample tool wasn't cooperating so I've included an Image.

Not sure if any of that made any sort of sense, if you need clarification please let me know. Any and all help is greatly appreciated!
