Hello,
I searched the forums and were able to find similar things but cannot
make it work for the action that I need.
I am trying to make B1 a mandatory cell if user puts data in A1. So if
there is data in A1 and B1 is empty, an error message should be
displayed on Save. I am sure it is not very hard but I am not much of
an Excel programmer.
Any help will be greatly appreciated...
Thanks in advance...Paste the following code into the code section of ThisWorkbook.Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
On Error GoTo ErrorHandler
If Sheets(1).Range(quot;A1quot;) lt;gt; quot;quot; And Sheets(1).Range(quot;B1quot;) = quot;quot; Then
Err.Raise vbObjectError 1, , _
quot;Value not in B1 when there is a Value in A1quot;
End If
Exit Sub
ErrorHandler:
Response = MsgBox(quot;Enter a Value into Cell B1quot;, vbOKOnly, quot;Your
Program Namequot;)
End SubI added the Cancel = True to cancel the save in case you wanted to
prevent the save.Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
On Error GoTo ErrorHandler
If Sheets(1).Range(quot;A1quot;) lt;gt; quot;quot; And Sheets(1).Range(quot;B1quot;) = quot;quot; Then
Err.Raise vbObjectError 1, , _
quot;Value not in B1 when there is a Value in A1quot;
End If
Exit Sub
ErrorHandler:
Response = MsgBox(quot;Enter a Value into Cell B1quot;, vbOKOnly, quot;Your
Program Namequot;)
Cancel = True
End SubThanks much for the code but nothing happens when I apply this. Have
you tested it?
emre
- Jul 20 Thu 2006 20:08
How can I make a cell mandatory?
close
全站熱搜
留言列表
發表留言