Mandatory Cell Inputs - Close Loop

The_Gigster

New Member
Joined
Nov 4, 2016
Messages
5
Hello all

I have a workbook that needs to go to various external stakeholders. I need them to fill a number of fields. I have named the range of these fields "Mandatory".

However, there are occasions where the external stakeholder may not be ready to fill the form in after viewing it and I need internal stakeholders to be able to view and use the workbook without the need for them to fill these fields and be able to close the file.

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim rng As Range
    Dim c As Variant
    Dim rngCount As Integer
    Dim CellCount As Integer


    Set rng = Range("Mandatory")
    rngCount = rng.Count


    CellCount = 0
    For Each c In rng
        If Len(c) > 0 Then
            CellCount = CellCount + 1
       
        End If
        
        Next c
    
    If CellCount <> rngCount Then
    
    MsgBox "Please fill Mandatory Fields", vbExclamation, "Required Entry"
    
   Cancel = True
        
    End If


Does anyone have any any ideas of what I can do to get around this loop?

Many thanks

The Gigster
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Try:
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Dim rng As Range
    Dim c As Variant
    Dim rngCount As Integer
    Dim CellCount As Integer
    Set rng = Range("Mandatory")
    rngCount = rng.Count
    CellCount = 0
    For Each c In rng
        If Len(c) > 0 Then
            CellCount = CellCount + 1
        End If
    Next c
    If CellCount <> rngCount Then
        If MsgBox("Do you wish to fill in the Mandatory Fields", vbYesNo, "Required Entry") = vbYes Then
            Cancel = True
        Else
            'do nothing
        End If
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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