Make a range of Cells Mandatory rather than writing separate code for each cell

Moseth

New Member
Joined
Sep 5, 2018
Messages
12
HI,
If Application.Sheets("Supplier Checklist").Range("C2").Cells = "" Then
Cancel = True
MsgBox "Please fill in the mandatory cells"
End If
For example if I want to make cells C2 to C21 all mandatory, is there an easier way to do this other tahn writing separate lines for each cell, how about if I wanted to make C2;C21 then D35-D49 mandatory. is there an easier way to code?
at the moment I am writing one line of code for one cell. Any easier way?
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
You can use the COUNTA function to count the number of cells with entries to see if they all have values, i.e.
Code:
If Application.WorksheetFunction.CountA(Range("C2:C21")) < 20 Then
[COLOR=#333333]    Cancel = True[/COLOR]
[COLOR=#333333]    MsgBox "Please fill in the mandatory cells"[/COLOR]
[COLOR=#333333]End If[/COLOR]
 
Upvote 0
How about
Code:
Sub MustFill()
   If Application.CountA(Sheets("Supplier Checklist").Range("C2:C21,D35:D49")) < 35 Then
      MsgBox "Please fill in the mandatory cells"
   End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,259
Members
452,626
Latest member
huntinghunter

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