有没有办法防止Excel关闭单元格B34>0和J34 = 0?
如果他们不填写B34,则不需要填写J34,工作簿可以关闭。
如果他们在B34中输入数据,我们也需要J34中的信息。
像这样:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Application.Sheets("Sheet1").Range("B34").Value > "" and _
Application.Sheets("Sheet1").Range("B34").Value = "" Then
Cancel = True
MsgBox "Please fill in the total % in cell J34"
End If
End Sub
在ThisWorkbook对象中:
Option Explicit
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim wb As Workbook
Dim ws As Worksheet
Set wb = ThisWorkbook
Set ws = wb.Sheets("Sheet1")
If ws.Range("B34").Value <> "" And ws.Range("J34").Value = "" Then
Cancel = True
MsgBox "Please fill in the total % in cell J34"
End If
End Sub