Very Sorry about that! I am new to the Forum. Does this work?


Hi, I am trying to write a macro in VBA that displays a message box if a user enters a number in a field, but fails to enter a description in the column to the left of it. Here is the code I have so far:

Sub MsgBox()
 
Dim r As Range
 Dim Buttons As String
 
Buttons = vbOKOnly + vbExclamation
 
For Each r In Range("E6:E16")
 
If r.Value = "" Then
 Exit Sub

 ElseIf r.Value <> "" Then
 If r.Offset(0, -1).Value <> "" Then
 Exit Sub
 ElseIf r.Offset(0, -1).Value = "" Then
 VBA.MsgBox "Please fill in the details section to continue.", Buttons, "Entry Required"
 End If
 End If
 Next r
 
End Sub
And here is a snippet of what the document looks like:

VBA example.PNG

Basically what I am trying to say here is if there is NO value in the BLUE cell then exit the macro because it is irrelevant, however, if there is a value in the BLUE cell and if there is a value in the cell to the left (YELLOW), then also exit the sub. BUT, if there is a value in the BLUE cell and there is NO value in the cell to the left (YELLOW), then MsgBox should appear that tells the user to enter a value in the YELLOW cell. The goal is to get users to provide some detail for the number they input and not just the number itself. This is for a budget.

If anyone could help it would be greatly appreciated!