Mandatory Field on Save and Send

Selbo33e

New Member
Joined
Aug 17, 2018
Messages
4
I have been reading up on mandatory fields and with the help of a few forums have successfully created macros to achieve this for filling in a cell before saving or before closing.

Question is, is there a option for mandatory cell to be filled before save and send?

Or do you have to disable the save and send option?

Thanks in advance
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Question is, is there a option for mandatory cell to be filled before save and send?

If you mean, does Excel have this option built-in ... the answer is no.

If this does not answer the question, please clarify.
 
Upvote 0
Apologies, I know that it does not have the option. The question should have been, is there a way of making a mandatory field before save and send
 
Upvote 0
.
Yes.

Are you referring to a cell on the worksheet or referring to a textbox on a userform ?
 
Upvote 0
.
Code:
Option Explicit




Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Cells(1, 2).Value = "" Then
    MsgBox "Cell B1 requires user input", vbInformation, "Enter Data"
    Cancel = True
End If
End Sub

Paste the above in ThisWorkbook module. You will need to change the cell reference to suit.
 
Upvote 0
.
Here is another macro with overkill. Confirmed it runs.

Code:
Option Explicit


Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Dim Start As Boolean
    Dim Rng1 As Range
    
    Dim Prompt As String, RngStr As String
    Dim Cell As Range
    
    Set Rng1 = Sheets("Sheet1").Range("B1")
    
    Prompt = "All cells must be completed prior to closing. "
       
    'highlights the blank cells
    For Each Cell In Rng1
        If Cell.Value = vbNullString Then
            Cell.Interior.ColorIndex = 6 '** color yellow
            If Start Then RngStr = RngStr & Cell.Parent.Name & vbCrLf
            Start = False
            RngStr = RngStr & Cell.Address(False, False) & ", "
        Else
            Cell.Interior.ColorIndex = 0 '** no color
        End If
    Next
      
    If RngStr <> "" Then
        MsgBox Prompt & "", vbCritical, "Incomplete Data"
        Cancel = True
    Else
        'saves the changes before closing
        ThisWorkbook.Save
        Cancel = False
    End If
  
    Set Rng1 = Nothing
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top