ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How can I make a cell mandatory? (https://www.excelbanter.com/excel-programming/352466-how-can-i-make-cell-mandatory.html)

alche

How can I make a cell mandatory?
 

Hello,

I searched the forums and were able to find similar things but canno
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 i
there is data in A1 and B1 is empty, an error message should b
displayed on Save. I am sure it is not very hard but I am not much o
an Excel programmer.

Any help will be greatly appreciated...

Thanks in advance..

--
alch
-----------------------------------------------------------------------
alche's Profile: http://www.hightechtalks.com/m90
View this thread: http://www.hightechtalks.com/t235327


Rob van Gelder[_4_]

How can I make a cell mandatory?
 
Add this code to the ThisWorkbook code module:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
With Worksheets("Sheet1")
If .Range("A1").Value < "" And .Range("B1").Value = "" Then
MsgBox "Mandatory cell not filled. No Save"
Cancel = True
End If
End With
End Sub

--
Rob van Gelder - http://www.vangelder.co.nz/


"alche" wrote in message
...

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...


--
alche
------------------------------------------------------------------------
alche's Profile: http://www.hightechtalks.com/m900
View this thread: http://www.hightechtalks.com/t2353270




Dave Peterson

How can I make a cell mandatory?
 
Why wait until the user tries to do a save?

Why not just use an adjacent cell and give the user a message:

=if(and(a1<"",b1=""),"Please enter a value in B1","")

As a user, I think I would appreciate the immediate feedback.

alche wrote:

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...

--
alche
------------------------------------------------------------------------
alche's Profile: http://www.hightechtalks.com/m900
View this thread: http://www.hightechtalks.com/t2353270


--

Dave Peterson

alche[_2_]

How can I make a cell mandatory?
 

Thank you very much! I inserted both and it is even better than
thought :

--
alch
-----------------------------------------------------------------------
alche's Profile: http://www.hightechtalks.com/m90
View this thread: http://www.hightechtalks.com/t235327



All times are GMT +1. The time now is 03:16 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com