Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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... |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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("A1") < "" And Sheets(1).Range("B1") = "" Then Err.Raise vbObjectError + 1, , _ "Value not in B1 when there is a Value in A1" End If Exit Sub ErrorHandler: Response = MsgBox("Enter a Value into Cell B1", vbOKOnly, "Your Program Name") End Sub |
#3
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
I 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("A1") < "" And Sheets(1).Range("B1") = "" Then Err.Raise vbObjectError + 1, , _ "Value not in B1 when there is a Value in A1" End If Exit Sub ErrorHandler: Response = MsgBox("Enter a Value into Cell B1", vbOKOnly, "Your Program Name") Cancel = True End Sub |
#4
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Thanks much for the code but nothing happens when I apply this. Have
you tested it? emre |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How to take a cell that has 3 values and make 2 more new lines | Excel Worksheet Functions | |||
Can I make a formula in Excel to display result in same cell? | Excel Worksheet Functions | |||
How can I make a cell mandatory and only accept a Y or N? | Excel Worksheet Functions | |||
Possible Lookup Table | Excel Worksheet Functions | |||
make a cell empty based on condition | Charts and Charting in Excel |