Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
 
Posts: n/a
Default How can I make a cell mandatory?

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   Report Post  
Posted to microsoft.public.excel.misc
 
Posts: n/a
Default How can I make a cell mandatory?

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   Report Post  
Posted to microsoft.public.excel.misc
 
Posts: n/a
Default How can I make a cell mandatory?

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   Report Post  
Posted to microsoft.public.excel.misc
 
Posts: n/a
Default How can I make a cell mandatory?

Thanks much for the code but nothing happens when I apply this. Have
you tested it?

emre

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to take a cell that has 3 values and make 2 more new lines Phil Excel Worksheet Functions 4 October 23rd 05 10:53 PM
Can I make a formula in Excel to display result in same cell? Neiko Excel Worksheet Functions 2 October 1st 05 10:36 PM
How can I make a cell mandatory and only accept a Y or N? Vicki Excel Worksheet Functions 1 June 23rd 05 07:23 PM
Possible Lookup Table Karen Excel Worksheet Functions 5 June 8th 05 09:43 PM
make a cell empty based on condition mpierre Charts and Charting in Excel 2 December 29th 04 01:01 PM


All times are GMT +1. The time now is 04:20 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"