Mandatory cell input

handri

New Member
Joined
Nov 25, 2017
Messages
43
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
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
51,494
Office Version
365
Platform
Windows
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:

handri

New Member
Joined
Nov 25, 2017
Messages
43
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:

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
22,806
A non code solution would be to put validation on all the cells of the worksheeet with the formula =($B$6<>"")
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
51,494
Office Version
365
Platform
Windows
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.
 

handri

New Member
Joined
Nov 25, 2017
Messages
43
thanks Sir

I will looking your solution soon

thanks
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
51,494
Office Version
365
Platform
Windows
You are welcome.
Glad we could help.
 

handri

New Member
Joined
Nov 25, 2017
Messages
43
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
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
51,494
Office Version
365
Platform
Windows
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
 

Forum statistics

Threads
1,082,367
Messages
5,365,028
Members
400,819
Latest member
Gossow

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top