Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
X = Sheet1.Range("A2")
Y = Sheet1.Range("A5")
Z = Sheet1.Range("A7")
If Not (X = "" Or X = " ") And (Y = "" Or Y = " ") Then
MsgBox "A2有內容-A5一定要輸入內容:否則無法存檔"
End If
If Not (X = "" Or X = " ") And (Z = "" Or Z = " ") Then
MsgBox "A2有內容-A7一定要輸入內容:否則無法存檔"
End If
End Sub作者: yen956 時間: 2016-3-8 09:57
試試看:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Rng As Range, E
'設定[A2],[A4:A5],[A7](舉例,可增減)一定要輸入值
Set Rng = Union([A2], [A4:A5], [A7])
'目前整張Worksheet任何地方有異動, 均會觸動本VBA.
'如想縮小觸動範圍為[A2],[A4:A5],[A7],請將下列前面之一撇「'」去掉
'If Intersect(Target, Rng) Is Nothing Then Exit Sub
If [A2] <> "" And Application.CountA(Rng) < Rng.Count Then