+ Reply to Thread
Results 1 to 14 of 14

mandatory cells

Hybrid View

  1. #1
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,621

    Re: mandatory cells

    For starters. This one will only give 1 messagebox when data is missing in one of the columns.

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
        If Application.CountA(Cells(Target.Row, 1).Resize(, 4)) <> 4 Then MsgBox "Missing data on Row " & Target.Row
    
    End Sub
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  2. #2
    Forum Contributor
    Join Date
    08-27-2019
    Location
    europa
    MS-Off Ver
    excel 2007
    Posts
    546

    Re: mandatory cells

    Thanks bakerman2 but the message must be referred to the cell to be inserted

  3. #3
    Forum Contributor
    Join Date
    08-27-2019
    Location
    europa
    MS-Off Ver
    excel 2007
    Posts
    546

    Re: mandatory cells

    Hi harrisonland your modified:
    Option Explicit
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
    Dim cella As Range
    Application.EnableEvents = False
    
    'Set cella = Range("A3") '<<< cella singola
    'Set cella = Cells(Target.Row, Target.Column) '<<< colonna
    
    Set cella = Cells(Target.Row, 1) '<<< cella singola
    
    With cella
    If .Value = "" Then
    
    'MsgBox "Devi inserire una data nella cella  A" & Target.Row & " ", vbCritical, "Errore!"
    MsgBox "You must enter a date in cell A" & Target.Row & " ", vbCritical, "Errore!"
    cella.Select
    Application.EnableEvents = True
    Exit Sub
    End If
    
    End With
    
    
    Set cella = Cells(Target.Row, 2) '<<< cella singola
    
    With cella
    If .Value = "" Then
    
    MsgBox "Devi inserire il reparto nella cella  B" & Target.Row & " ", vbCritical, "Errore!"
    cella.Select
    Application.EnableEvents = True
    Exit Sub
    End If
    
    End With
    
    
    
    Set cella = Cells(Target.Row, 3) '<<< cella singola
    
    With cella
    If .Value = "" Then
    
    MsgBox "Devi inserire l'operatore nella cella  C" & Target.Row & " ", vbCritical, "Errore!"
    cella.Select
    Application.EnableEvents = True
    Exit Sub
    End If
    
    End With
    
    
    
    Set cella = Cells(Target.Row, 4) '<<< cella singola
    
    With cella
    If .Value = "" Then
    
    MsgBox "Devi inserire il tempo nella cella  D" & Target.Row & " ", vbCritical, "Errore!"
    cella.Select
    Application.EnableEvents = True
    Exit Sub
    End If
    
    End With
    
    
    
    Application.EnableEvents = True
    End Sub
    work well.
    Thans you
    xam

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Mandatory Cells
    By Rich789 in forum Excel General
    Replies: 1
    Last Post: 08-24-2017, 08:33 AM
  2. VBA - mandatory cells in excel
    By bees2cute in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-17-2016, 09:02 AM
  3. How can I make multiple cells mandatory if new rows are used with some cells left blank?
    By markbarnett in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-11-2015, 07:06 AM
  4. Mandatory field required message when user skips mandatory fields
    By Bharathi27 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-11-2013, 05:12 AM
  5. Mandatory Cells
    By MYQ in forum Excel General
    Replies: 7
    Last Post: 10-12-2012, 02:16 PM
  6. Mandatory cells
    By john.mk in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 02-25-2010, 11:03 PM
  7. [SOLVED] Mandatory Cells
    By Mel1221 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-05-2006, 05:10 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1