VBA问题 – 试图使多个单元格强制保存Excel文档

在一个Excel文档上工作,它需要一些单元格才能被保存。 我能够用下面的代码来解决这个问题。

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) If Cells(6, 5).Value = "" Then MsgBox "Cell E6 requires user input", vbInformation, "Kutools for Excel" Cancel = True Exit Sub End If If Cells(8, 5).Value = "" Then MsgBox "Cell E8 requires user input", vbInformation, "Kutools for Excel" Cancel = True Exit Sub End If If Cells(10, 5).Value = "" Then MsgBox "Cell E10 requires user input", vbInformation, "Kutools for Excel" Cancel = True Exit Sub End If 

我遇到的问题是,如果特定的单元格被填充,则其他单元格是必需的,才能保存文档。 我已经尝试了isEmpty函数,但它仍然无法正常工作。 请帮忙!

使用If Cells(1,1).Value <> ""然后需要像你一直在做的其他单元格。 喜欢这个:

 If Cells(1,1).Value <> "" Then If Cells(10, 5).Value = "" Then MsgBox "Cell E10 requires user input", vbInformation, "Kutools for Excel" Cancel = True Exit Sub End If End If