+ Reply to Thread
Results 1 to 4 of 4

How can I make a cell mandatory?

Hybrid View

  1. #1
    eakkas@gmail.com
    Guest

    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. #2
    edessary@gmail.com
    Guest

    Re: 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. #3
    edessary@gmail.com
    Guest

    Re: 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. #4
    eakkas@gmail.com
    Guest

    Re: 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1