2 sets of ranges are here but under the same column.
When you share a workbook to other users for doing a survey which needs the real name registration, for instance, every user under investigation needs to enter their name in B1. But in some times, some users may close the workbook after investigation without entering their names. In this article, I introduce a VBA to make a particular cell mandatory before closing the workbook.
|Kutools for Excel's Protect Worksheet function can quickly protect multiple sheets or the whole workbook at once.|
Office Tab: Bring powerful tabs to Office (include Excel), just like Chrome, Safari, Firefox and Internet Explorer. Save you half the time, and reduce thousands of mouse clicks for you. 30-day Unlimited Free Trial
Kutools for Excel: Save 71% of your time and solve 82% Excel problems for you. 300+ advanced tools designed for 1500+ work scenario, make Excel much easy and increase productivity immediately.60-day Unlimited Free Trial
|Kutools for Excel, with more than 120 handy Excel functions, enhance your working efficiency and save your working time.|
1. Enable the workbook that contains the mandatory cell, and press Alt + F11 keys to open Microsoft Visual Basic for Applications window.
2. In the Project pane, double click ThisWorkbook, and go to select Workbook and BeforeClose from right section list, then paste below code to the script. See screenshot:
VBA: Make a cell mandatory
If Cells(1, 2).Value = "" Then MsgBox "Cell B1 requires user input", vbInformation, "Kutools for Excel" Cancel = True End If
3. Then save this code and close this popping window. Now, if the cell B1 is blank when you close the workbook, below dialog will pop out to remind you to enter something in B1. See screenshot:
Tip: You can change cell B1 to other cells you want.