私の列Aには、「はい」または「いいえ」を選択できる選択肢があります。両方の選択に必要なセルがあります。ユーザーがVBAで保存したときにエラーをスローする方法
Example:
If User selects "YES"
Mandatory cells will be in Colum A, D and E
If User selects "No"
Mandatory cells will be in Colum B, C and G
「行1」では、ユーザーが「はい」を選択してA1とE1に値を入力したが、セルD1に値を追加するのを忘れたとします。 行2では、ユーザーは「いいえ」を選択してB2とC2に値を入力し、セルG2に値を入力するのを忘れました。
彼は私が "は、以下のセルの値を入力しますというエラーをスローしたい、セーブヒットD1、G2
私は以下のコードがあります。。
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim Target As Range
If Not Intersect(Target, Range("A:A")) Is Nothing Then
If Target = "YES" Then
For i = 1 To 15
If Target.Offset(0, i).Value = "" Then
MsgBox "Enter values on the mandatory cells (green)", vbCritical, ""
End If
Next i
Cancel = True
ElseIf Target = "NO" Then
For i = 16 To 30
If Target.Offset(0, i).Value = "" Then
MsgBox "Enter values on the mandatory cells (green)", vbCritical, ""
End If
Next i
Cancel = True
End If
End If
End Sub
[チェックアウト'Workbook_BeforeSave'イベント](https://msdn.microsoft.com/en-us/library/office/ff840057.aspx) – BruceWayne