VBA or data validation to create a fillable form, (with multiple cells required) that must be filled in before saving

suzette0735

New Member
Joined
Jul 12, 2023
Messages
24
Office Version
  1. 365
Platform
  1. Windows
Hello, I need your help today please.
I am creating a fillable form in excel and need to have certain fields completed before saving the document to prevent incomplete forms. However, I also want these to be blank when opening the document. Is this even possible? I am new to VBA and have tried data validation, but it appears I have to input data In the cell with this, and can cannot leave it blank. Thank you in advance!
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
usage:
If IsValidForm() Then
msgbox "Saved"
'close form
endif


Code:
Private Function IsValidForm() As Boolean
Dim vMsg
Select Case True
   Case IsNull(txtLastName)
        vMsg = "Last Name is missing"
   Case IsNull(cboState)
      vMsg = "State is missing"
End Select

If vMsg <> "" Then MsgBox vMsg, vbCritical, "Required Field"
IsValidForm = vMsg = ""
End Function
 
Upvote 0
Thank you Ranman256!, I appreciate your help! As i am very new to this I want to make sure I understand correctly so i can use this formula in VBA and for each one of the fields that i need to be completed in order for it to save when i close?
For example if I have a drop down where they can select type of occupancy: one is left blank so I can start the form on there , one is occupied and one is not occupied. I want them to have to select one of the two with text, i would put what you have above...do i have to name my drop down list "occupancy for this to work? And I need the quantity filled in or the cost in a column, am i doing it right in the formula?
Private Function IsValidForm() As Boolean
Dim vMsg
Select Case True
Case IsNull(txtOccupancy)
vMsg = "Occupancy is missing"
Case IsNull(numQuantity)
vMsg = "Quantity is missing"
End Select

If vMsg <> "" Then MsgBox vMsg, vbCritical, "Required Field"
IsValidForm = vMsg = ""
End Function

Also if i have a cell for Customer name and the one i need filled is right next to it does the same concept apply?
 
Upvote 0
usage:
If IsValidForm() Then
msgbox "Saved"
'close form
endif


Code:
Private Function IsValidForm() As Boolean
Dim vMsg
Select Case True
   Case IsNull(txtLastName)
        vMsg = "Last Name is missing"
   Case IsNull(cboState)
      vMsg = "State is missing"
End Select

If vMsg <> "" Then MsgBox vMsg, vbCritical, "Required Field"
IsValidForm = vMsg = ""
End Function
Thank you Ranman256!, I appreciate your help! As i am very new to this I want to make sure I understand correctly so i can use this formula in VBA and for each one of the fields that i need to be completed in order for it to save when i close?
For example if I have a drop down where they can select type of occupancy: one is left blank so I can start the form on there , one is occupied and one is not occupied. I want them to have to select one of the two with text, i would put what you have above...do i have to name my drop down list "occupancy for this to work? And I need the quantity filled in or the cost in a column, am i doing it right in the formula?
Private Function IsValidForm() As Boolean
Dim vMsg
Select Case True
Case IsNull(txtOccupancy)
vMsg = "Occupancy is missing"
Case IsNull(numQuantity)
vMsg = "Quantity is missing"
End Select

If vMsg <> "" Then MsgBox vMsg, vbCritical, "Required Field"
IsValidForm = vMsg = ""
End Function
 
Upvote 0
Code:
Select Case True
  Case IsNull(txtOccupancy) and IsNull(numQuantity)
      vMsg = "Occupancy or Quantity must be filled"
End Select
 
Upvote 0
Hi there, I pleas need VBA code for a macro that opens a workbook, calculates the difference between two values in the same sheet, and displays the result in column 3.Thanks.Willem
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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