Mandatory cell input

handri

Board Regular
Joined
Nov 25, 2017
Messages
88
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hi,

I looking for a new vba code for these.
In my workbook. I need to make B6 cell as mandatory or need to fill first before you can do other work in workbook.
Also a message popup if they not fill the B6 FIRST. Meant after save and open if B6 are filled you can continue your work.

Thank you
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
You could put in a Worksheet_Change event that runs automatically whenever they update any cell, and if B6 is not populated, it will remove what they did and tell them that they need to populate cell B6 first.

Here is the code. Just right-click on the sheet tab name at the bottom of the screen, select "View Code", and paste this code in the VB Editor window.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

'   Check to see if B6 is populated
    If Len(Range("B6")) = 0 Then
        Application.EnableEvents = False
        Target.ClearContents
        MsgBox "You must populate cell B6 before doing any work!", vbOKOnly, "ENTRY ERROR!"
        Application.EnableEvents = True
    End If
    
End Sub
There are other ways to approach this too. Alternatively, we could come up with VBA code that runs on Open that locks all cells in cell B6 is blank, and only unlocks it when B6 is populated.

Of course, all of this is dependent upon them enabling VBA when they open the workbook. If they don't, it will bypass all the code. I have seen people get clever and hide everything, and have VBA code that unhides it upon opening. So if they do not enable the VBA code, they will not see the sheets at all.
 
Last edited:
Upvote 0
Hi joe,

thank for your reply, but I have a code present in same workbook
My code as below


Private Sub Worksheet_Calculate()
If Me.Range("F6").Value > 0 Then _
MsgBox "SALAH MODEL SCAN !! PERIKSA SEMULA PCB!"
End Sub


I have no idea to combine your code given with mine

thank you

EDIT

OK fine now I paste as below, now everything is ok.. thank you
Private Sub Worksheet_Calculate()
If Me.Range("F6").Value > 0 Then _
MsgBox "SALAH MODEL SCAN !! PERIKSA SEMULA PCB!"
End Sub


Private Sub Worksheet_Change(ByVal Target As Range)


' Check to see if B6 is populated
If Len(Range("B6")) = 0 Then
Application.EnableEvents = False
Target.ClearContents
MsgBox "You must populate cell B6 before doing any work!", vbOKOnly, "ENTRY ERROR!"
Application.EnableEvents = True
End If

End Sub
 
Last edited:
Upvote 0
A non code solution would be to put validation on all the cells of the worksheeet with the formula =($B$6<>"")
 
Upvote 0
I have no idea to combine your code given with mine
You don't combine them. That is a totally different procedure (Worksheet_Calculate vs. Worksheet_Change).
You just paste my code below what you already have there.
 
Upvote 0
thanks Sir

I will looking your solution soon

thanks
 
Upvote 0
You are welcome.
Glad we could help.
 
Upvote 0
How to combine these 2 vba code in same sheet, error in result. But in single code done well..

code 1

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Target.Value = "" Then Exit Sub
If Not Intersect(Target, Range("A:A")) Is Nothing Then
If Cells(Target.Row, "C").Value = "WRONG" Then
MsgBox "Scan a wrong item", vbCritical
Target.Select
End If
End If
End Sub

code 2

Private Sub Worksheet_Change(ByVal Target As Range)


' Check to see if B6 is populated
If Len(Range("B6")) = 0 Then
Application.EnableEvents = False
Target.ClearContents
MsgBox "You must populate cell B6 before doing any work!", vbOKOnly, "ENTRY ERROR!"
Application.EnableEvents = True
End If

End Sub

thanks
 
Upvote 0
Try this:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.Count > 1 Then Exit Sub
    
'***Code block 1***
'   Check to see if B6 is populated
    If Len(Range("B6")) = 0 Then
        Application.EnableEvents = False
        Target.ClearContents
        MsgBox "You must populate cell B6 before doing any work!", vbOKOnly, "ENTRY ERROR!"
        Application.EnableEvents = True
    End If

'***Code block 2***
    If Target.Value = "" Then Exit Sub
    If Not Intersect(Target, Range("A:A")) Is Nothing Then
        If Cells(Target.Row, "C").Value = "WRONG" Then
            MsgBox "Scan a wrong item", vbCritical
            Target.Select
        End If
    End If
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,378
Members
448,955
Latest member
BatCoder

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