+ Reply to Thread
Results 1 to 14 of 14

mandatory cells

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

    mandatory cells

    Hello to all.
    This macro:
    Please Login or Register  to view this content.
    you must enter a date in cell A mandatory
    Now I added mandatory too column B / C / D but the warning appears 3 times, but it should only appear in the selected cell.
    Please Login or Register  to view this content.
    you can edit?
    xam
    Attached Files Attached Files
    Last edited by xam99; 01-12-2020 at 04:47 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    06-22-2018
    Location
    Blackpool, England
    MS-Off Ver
    2019
    Posts
    408

    Re: mandatory cells

    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!"

    End If

    End With
    ' ...... etc

    End Sub
    Why not just exit the sub after the first failed test?

    e.g.
    Please Login or Register  to view this content.
    HTH
    Tim


    EDIT
    Remember to re-enable events!

    Please Login or Register  to view this content.
    Last edited by harrisonland; 01-12-2020 at 05:50 AM.

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

    Re: mandatory cells

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

    Please Login or Register  to view this content.
    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.

  4. #4
    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

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

    Re: mandatory cells

    Hi harrisonland your modified:
    Please Login or Register  to view this content.
    work well.
    Thans you
    xam

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

    Re: mandatory cells

    Please Login or Register  to view this content.

  7. #7
    Valued Forum Contributor
    Join Date
    06-22-2018
    Location
    Blackpool, England
    MS-Off Ver
    2019
    Posts
    408

    Re: mandatory cells

    Haha! Bakerman2's solution is far more elegant (as usual), why not tweak it a bit to make it flexible:

    Please Login or Register  to view this content.
    Tim
    Never stop learning!
    <--- please consider *-ing !

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

    Re: mandatory cells

    Thanks bakerman2 and harrisonland
    the warning must be referred to the cell, see my first thread
    data / reparto / operatore / tempo

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

    Re: mandatory cells

    Didn't notice there was always a different message.

    Please Login or Register  to view this content.

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

    Re: mandatory cells

    Hi bakerman2 the new modified work well.
    i tried moving the required cells now are:
    A / D and E / F but as I did it doesn't work
    Please Login or Register  to view this content.

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

    Re: mandatory cells

    Post an example file with the new layout.

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

    Re: mandatory cells

    Here is an example.
    Another thing must start from row 3

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

    Re: mandatory cells

    Try this then.
    Please Login or Register  to view this content.

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

    Re: mandatory cells

    Thanks bakerman2 I think it is correct now.
    To be sure I have to try the macro in the office where I work.
    A greeting and thanks again.
    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. 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