我一直在想弄清楚如何为这个数据库页面创建动态范围,以便项目在保存工作簿之前检查相位数据是否缺失。数据库页面将继续增长,并且不确定如何使此范围动态化。
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim rsave As Range
Dim cell As Range
Sheets("Database").Select
Set rsave = Range("a7:a125")
For Each cell In rsave
If cell = "" Then
Dim missdata
missdata = MsgBox("Missing Phase Data", vbOKOnly, "Missing Phase Data")
Cancel = True
cell.Select
Exit For
End If
Next cell
End Sub
答案 0 :(得分:0)
这将为您提供缺失项目的完整故事:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim msg As String, N As Long, cl As Range
N = Cells(Rows.Count, 1).End(xlUp).Row +1
Dim r As Range
Set r = Range("A7:A" & N)
For Each cl In r
If cl.Value = "" Then
msg = msg & vbCrLf & cl.Address(0, 0)
End If
Next cl
If msg = "" Then Exit Sub
MsgBox msg
Cancel = True
End Sub