强制合并单元格input为Excel 2016

我有一个从D4到H4的合并单元格,我希望单元格是强制性的。 我曾尝试下面的代码,但不工作。

Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim c As Range Dim cel As Range Set c = Range("D4:H4") Application.EnableEvents = False If Not Intersect(Target, c) Is Nothing Then For Each cel In c If cel.Text = "" Then Application.Goto reference:=c, Scroll:=True MsgBox ("Field Cannot Be Blank") Exit For End If Next cel End If Application.EnableEvents = True End Sub 

我还有另一个细胞需要强制性H2。 这个代码已经工作了,我想把D4的代码和H4和H2结合在一起。

 Private Sub Workbook_BeforeClose(Cancel As Boolean) If Cells(2, 8).Value = "" Then MsgBox "Cell H2 requires user input", vbInformation, "Please filled up the mandatory cells" Cancel = True End If End Sub 

任何帮助和build议表示赞赏。

感谢@Rik Sportel,我尝试将单元格重新合并,并应用elseif语句,现在就可以工作。

 Private Sub Workbook_BeforeClose(Cancel As Boolean) If Cells(4, 4).Value = "" Then MsgBox "Cell D4 requires user input", vbInformation, "Please filled up the mandatory cells" Cancel = True ElseIf Cells(2, 8).Value = "" Then MsgBox "Cell H2 requires user input", vbInformation, "Please filled up the mandatory cells" Cancel = True End If End Sub