+ Reply to Thread
Results 1 to 28 of 28

how to check data has been entered before submitting

Hybrid View

  1. #1
    Registered User
    Join Date
    09-13-2009
    Location
    Wales
    MS-Off Ver
    Excel 2003
    Posts
    57

    how to check data has been entered before submitting

    Hi Guys

    this will be a difficult one, maybe not for some but for most i would think

    i currently have an email button setup, so when the person has filled in the sheet and clicks the button it sends the active worksheet to the specified email address in the code

    i need an extra step in this code to check that data has been filled in, in certain cells before the email is sent

    for example i have numberous cells but in cell i17 if something is entered then there must be something entered in cell i19. If there is nothing filled in cell i17 then the data validation can ignore this. Basically it needs to check that corresponding cell(s) are filled in "if" the first cell is filled in (make sense?)

    i would also like it to check certain cells are filled in (mandatory cells)

    here is the email button code, is there anything i can implement in that to produce the above results? or if this cannot be achieved maybe a warning box to pop up before it sends to say "Please make sure everything is filled in corrently before submitting" (something like that)

    thanks for any help

    Sub Mail_ActiveSheet()
    'Working in 97-2007
        Dim FileExtStr As String
        Dim FileFormatNum As Long
        Dim Sourcewb As Workbook
        Dim Destwb As Workbook
        Dim TempFilePath As String
        Dim TempFileName As String
    
        With Application
            .ScreenUpdating = False
            .EnableEvents = False
        End With
    
        Set Sourcewb = ActiveWorkbook
    
        'Copy the sheet to a new workbook
        ActiveSheet.Copy
        Set Destwb = ActiveWorkbook
    
        'Determine the Excel version and file extension/format
        With Destwb
            If Val(Application.Version) < 12 Then
                'You use Excel 97-2003
                FileExtStr = ".xls": FileFormatNum = -4143
            Else
                'You use Excel 2007
                'We exit the sub when your answer is NO in the security dialog that you only
                'see  when you copy a sheet from a xlsm file with macro's disabled.
                If Sourcewb.Name = .Name Then
                    With Application
                        .ScreenUpdating = True
                        .EnableEvents = True
                    End With
                    MsgBox "Your answer is NO in the security dialog"
                    Exit Sub
                Else
                    Select Case Sourcewb.FileFormat
                    Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
                    Case 52:
                        If .HasVBProject Then
                            FileExtStr = ".xlsm": FileFormatNum = 52
                        Else
                            FileExtStr = ".xlsx": FileFormatNum = 51
                        End If
                    Case 56: FileExtStr = ".xls": FileFormatNum = 56
                    Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
                    End Select
                End If
            End If
        End With
    
        '    'Change all cells in the worksheet to values if you want
        '    With Destwb.Sheets(1).UsedRange
        '        .Cells.Copy
        '        .Cells.PasteSpecial xlPasteValues
        '        .Cells(1).Select
        '    End With
        '    Application.CutCopyMode = False
    
        'Save the new workbook/Mail it/Delete it
        TempFilePath = Environ$("temp") & "\"
        TempFileName = "Absense Report"
    
        With Destwb
            .SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
            On Error Resume Next
            .SendMail "", _
                      "Absence Report - " & Range("E10").Text & " / " & Range("W10").Text & " - " & Range("E13").Text
            On Error GoTo 0
            .Close SaveChanges:=False
        End With
    
        'Delete the file you have send
        Kill TempFilePath & TempFileName & FileExtStr
    
        With Application
            .ScreenUpdating = True
            .EnableEvents = True
        End With
    End Sub
    Last edited by techmob; 01-20-2010 at 08:38 AM.

  2. #2
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: how to check data has been entered before submitting

    The way you describe it, the problem does look to hard. Maybe there's more to it than I see right now. Let's see if I understand. The following code will exit your routine after displaying a message. Add more if tests to perform other validation
    with ActiveSheet
        ' test cells I17 and I 19
        If (.Cells(17,9).Value <> "" and .Cells(19,9).Value) then
            MsgBox "Data missing in cell I17 or I19"
            Exit Sub
        End If
    You can insert this code anywhere before mailing the file. I would suggest doing the validation the first thing.

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: how to check data has been entered before submitting

    It would be simpler to add Data Validation to the actual cells
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Registered User
    Join Date
    09-13-2009
    Location
    Wales
    MS-Off Ver
    Excel 2003
    Posts
    57

    Re: how to check data has been entered before submitting

    blane thanks for the reply, i have added that code above my email code but i get a compile error

    Roy, i have not heard of that before is it easy to do

    thanks

  5. #5
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: how to check data has been entered before submitting

    Put "End With" after the last line. Sorry.

  6. #6
    Registered User
    Join Date
    09-13-2009
    Location
    Wales
    MS-Off Ver
    Excel 2003
    Posts
    57

    Re: how to check data has been entered before submitting

    thanks, but i still get a compile error

  7. #7
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: how to check data has been entered before submitting

    Can you tell me what the compile error is?

  8. #8
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: how to check data has been entered before submitting

    Change the "if" test line to
        If (.Cells(17, 9).Value <> "" And .Cells(19, 9).Value = "") Then

  9. #9
    Registered User
    Join Date
    09-13-2009
    Location
    Wales
    MS-Off Ver
    Excel 2003
    Posts
    57

    Re: how to check data has been entered before submitting

    invalid outside procedure and then highlights the "With ActiveSheet"

    this is with the latest edits

    thanks

  10. #10
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: how to check data has been entered before submitting

    Oh, you have to wrap this code in a procedure (Sub or Function) before will can be run. Put it after your Sub Mail_ActiveSheet() statement.

  11. #11
    Registered User
    Join Date
    09-13-2009
    Location
    Wales
    MS-Off Ver
    Excel 2003
    Posts
    57

    Re: how to check data has been entered before submitting

    i can't seem to get it to work, but thanks for your effort

    i think i have found a way around it by having the validation on each box which alerts the user to the corresponding cell

    thanks for your help, i may need to come back to this thread if this doesn't work out

    thanks

  12. #12
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: how to check data has been entered before submitting

    Post your workbook and we can debug it for you.

  13. #13
    Registered User
    Join Date
    09-13-2009
    Location
    Wales
    MS-Off Ver
    Excel 2003
    Posts
    57

    Re: how to check data has been entered before submitting

    Hi, back again

    the original sheet that this help was requested for was completed without the need to check boxes. but i have started a new form which needs to have a print button but before it prints it needs to check certain boxes/cells that data has been entered, if there has been no data enterned then it stops and prompts the user to fill in the cells. once filled they can click the print button and it prints

    is this something that can be done with the code you gave previously?

    thanks
    Last edited by techmob; 02-02-2010 at 08:13 AM.

  14. #14
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: how to check data has been entered before submitting

    If you post the workbook, I'll take a look at what you are doing.
    Bob
    Click my star if my answer helped you. Mark the thread as [SOLVED] if it has been.

  15. #15
    Registered User
    Join Date
    09-13-2009
    Location
    Wales
    MS-Off Ver
    Excel 2003
    Posts
    57

    Re: how to check data has been entered before submitting

    Hi Blane

    i have added the workbook

    I have nearly got it to work with the code below


     
    
    Private Sub Workbook_BeforePrint(Cancel As Boolean)
    
        If Sheet1.Range("E10").Value = "" Then
    
             MsgBox "Please Enter a First Name"
    
            Cancel = True
    
        ElseIf Sheet1.Range("M10").Value = "" Then
    
             MsgBox "Please Enter a Surname"
    
            Cancel = True
    
        End If
    
    End Sub


    which works fine, but again if i add any more i get an error with the below code, can you see what i have done wrong?



    it says compile error block if without end if







    Private Sub Workbook_BeforePrint(Cancel As Boolean)
    
        If Sheet1.Range("E10").Value = "" Then
    
             MsgBox "Please Enter a First Name"
    
            Cancel = True
    
        ElseIf Sheet1.Range("M10").Value = "" Then
    
             MsgBox "Please Enter a Surname"
    
            Cancel = True
    
         If Sheet1.Range("E13").Value = "" Then
    
             MsgBox "Please Enter a First Name"
    
            Cancel = True
    
        ElseIf Sheet1.Range("M13").Value = "" Then
    
             MsgBox "Please Enter a Surname"
    
            Cancel = True
    
             If Sheet1.Range("G15").Value = "" Then
    
             MsgBox "Please Enter a First Name"
    
            Cancel = True
    
        ElseIf Sheet1.Range("K15").Value = "" Then
    
             MsgBox "Please Enter a Surname"
    
            Cancel = True
    
             If Sheet1.Range("O15").Value = "" Then
    
             MsgBox "Please Enter a First Name"
    
            Cancel = True
    
        ElseIf Sheet1.Range("G18").Value = "" Then
    
             MsgBox "Please Enter a Surname"
    
            Cancel = True
    
             If Sheet1.Range("K18").Value = "" Then
    
             MsgBox "Please Enter a First Name"
    
            Cancel = True
    
        ElseIf Sheet1.Range("O18").Value = "" Then
    
             MsgBox "Please Enter a Surname"
    
            Cancel = True
    
             If Sheet1.Range("E23").Value = "" Then
    
             MsgBox "Please Enter a First Name"
    
            Cancel = True
    
        ElseIf Sheet1.Range("I23").Value = "" Then
    
             MsgBox "Please Enter a Surname"
    
            Cancel = True
    
             If Sheet1.Range("M23").Value = "" Then
    
             MsgBox "Please Enter a First Name"
    
            Cancel = True
    
        ElseIf Sheet1.Range("Q23").Value = "" Then
    
             MsgBox "Please Enter a Surname"
    
            Cancel = True
    
             If Sheet1.Range("V23").Value = "" Then
    
             MsgBox "Please Enter a First Name"
    
            Cancel = True
    
        ElseIf Sheet1.Range("E28").Value = "" Then
    
             MsgBox "Please Enter a Surname"
    
            Cancel = True
    
             If Sheet1.Range("M28").Value = "" Then
    
             MsgBox "Please Enter a First Name"
    
            Cancel = True
    
        ElseIf Sheet1.Range("V28").Value = "" Then
    
             MsgBox "Please Enter a Surname"
    
            Cancel = True
    
             If Sheet1.Range("E31").Value = "" Then
    
             MsgBox "Please Enter a First Name"
    
            Cancel = True
    
        ElseIf Sheet1.Range("M31").Value = "" Then
    
             MsgBox "Please Enter a Surname"
    
            Cancel = True
    
             If Sheet1.Range("O33").Value = "" Then
    
             MsgBox "Please Enter a First Name"
    
            Cancel = True
    
        ElseIf Sheet1.Range("G33").Value = "" Then
    
             MsgBox "Please Enter a Surname"
    
            Cancel = True
    
             If Sheet1.Range("V33").Value = "" Then
    
             MsgBox "Please Enter a First Name"
    
            Cancel = True
    
        ElseIf Sheet1.Range("E38").Value = "" Then
    
             MsgBox "Please Enter a Surname"
    
            Cancel = True
    
             If Sheet1.Range("O38").Value = "" Then
    
             MsgBox "Please Enter a First Name"
    
            Cancel = True
    
        ElseIf Sheet1.Range("E41").Value = "" Then
    
             MsgBox "Please Enter a Surname"
    
            Cancel = True
    
             If Sheet1.Range("O41").Value = "" Then
    
             MsgBox "Please Enter a First Name"
    
            Cancel = True
    
        ElseIf Sheet1.Range("F45").Value = "" Then
    
             MsgBox "Please Enter a Surname"
    
            Cancel = True
    
             If Sheet1.Range("G45").Value = "" Then
    
             MsgBox "Please Enter a First Name"
    
            Cancel = True
    
        ElseIf Sheet1.Range("H45").Value = "" Then
    
             MsgBox "Please Enter a Surname"
    
            Cancel = True
    
             If Sheet1.Range("I45").Value = "" Then
    
             MsgBox "Please Enter a First Name"
    
            Cancel = True
    
        ElseIf Sheet1.Range("J45").Value = "" Then
    
             MsgBox "Please Enter a Surname"
    
            Cancel = True
    
             If Sheet1.Range("K45").Value = "" Then
    
             MsgBox "Please Enter a First Name"
    
            Cancel = True
    
        ElseIf Sheet1.Range("Q44").Value = "" Then
    
             MsgBox "Please Enter a Surname"
    
            Cancel = True
    
             If Sheet1.Range("E49").Value = "" Then
    
             MsgBox "Please Enter a First Name"
    
            Cancel = True
    
        ElseIf Sheet1.Range("F49").Value = "" Then
    
             MsgBox "Please Enter a Surname"
    
            Cancel = True
    
        ElseIf Sheet1.Range("H49").Value = "" Then
    
             MsgBox "Please Enter a Surname"
    
            Cancel = True
    
             If Sheet1.Range("G49").Value = "" Then
    
             MsgBox "Please Enter a First Name"
    
            Cancel = True
    
        ElseIf Sheet1.Range("I49").Value = "" Then
    
             MsgBox "Please Enter a Surname"
    
            Cancel = True
    
             If Sheet1.Range("J49").Value = "" Then
    
             MsgBox "Please Enter a First Name"
    
            Cancel = True
    
        ElseIf Sheet1.Range("K49").Value = "" Then
    
             MsgBox "Please Enter a Surname"
    
            Cancel = True
    
             ElseIf Sheet1.Range("L49").Value = "" Then
    
             MsgBox "Please Enter a Surname"
    
            Cancel = True
    
        End If
    
    End Sub
    Last edited by techmob; 02-05-2010 at 12:18 PM.

  16. #16
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: how to check data has been entered before submitting

    You have several places where you have an "If" rather than an "ElseIf". Replace them and you should be fine.

  17. #17
    Registered User
    Join Date
    09-13-2009
    Location
    Wales
    MS-Off Ver
    Excel 2003
    Posts
    57

    Re: how to check data has been entered before submitting

    Quote Originally Posted by blane245 View Post
    You have several places where you have an "If" rather than an "ElseIf". Replace them and you should be fine.
    thanks for that

    so change all "if" to "elseif" ?

    thanks

  18. #18
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: how to check data has been entered before submitting

    Except the first one.

  19. #19
    Registered User
    Join Date
    09-13-2009
    Location
    Wales
    MS-Off Ver
    Excel 2003
    Posts
    57

    Re: how to check data has been entered before submitting

    i get the same error

    thanks

    Private Sub Workbook_BeforePrint(Cancel As Boolean)
    If Sheet1.Range("E10").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("M10").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("E13").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("M13").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    If Sheet1.Range("G15").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("K15").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("O15").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("G18").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("K18").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("O18").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("E23").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("I23").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("M23").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("Q23").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("V23").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("E28").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("M28").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("V28").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("E31").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("M31").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("O33").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("G33").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("V33").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("E38").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("O38").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("E41").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("O41").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("F45").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("G45").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("H45").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("I45").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("J45").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("K45").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("Q44").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("E49").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("F49").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("H49").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("G49").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("I49").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("J49").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("K49").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("L49").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    End If
    End Sub

  20. #20
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: how to check data has been entered before submitting

    you missed one
    Option Explicit
    
    Private Sub Workbook_BeforePrint(Cancel As Boolean)
    If Sheet1.Range("E10").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("M10").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("E13").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("M13").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("G15").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("K15").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("O15").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("G18").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("K18").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("O18").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("E23").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("I23").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("M23").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("Q23").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("V23").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("E28").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("M28").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("V28").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("E31").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("M31").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("O33").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("G33").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("V33").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("E38").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("O38").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("E41").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("O41").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("F45").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("G45").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("H45").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("I45").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("J45").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("K45").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("Q44").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("E49").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("F49").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("H49").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("G49").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("I49").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("J49").Value = "" Then
    MsgBox "Please Enter a First Name"
    Cancel = True
    ElseIf Sheet1.Range("K49").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    ElseIf Sheet1.Range("L49").Value = "" Then
    MsgBox "Please Enter a Surname"
    Cancel = True
    End If
    End Sub

  21. #21
    Registered User
    Join Date
    09-13-2009
    Location
    Wales
    MS-Off Ver
    Excel 2003
    Posts
    57

    Re: how to check data has been entered before submitting

    ooops, my bad

    thanks for that it works, appreciate your help with that

    i am probably complicating things here, but is there anyway i can have that code to highlight the cells that need editing, so the user knows which ones to fill in to?

    thanks

  22. #22
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: how to check data has been entered before submitting

    Use a scheme like
    If Sheet1.Range("E10").Value = "" Then
    MsgBox "Please Enter a First Name"
    Sheet1.Range("E10").Select
    Cancel = True
    note the line where cell E10 is selected. You would add a line like this after each call to MsgBox selected the cell of interest.

  23. #23
    Registered User
    Join Date
    09-13-2009
    Location
    Wales
    MS-Off Ver
    Excel 2003
    Posts
    57

    Re: how to check data has been entered before submitting

    i like that, works well thanks

    is there anyway to make the cell go a colour and disappear when the user enters data?

    thanks

  24. #24
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: how to check data has been entered before submitting

    Quote Originally Posted by techmob View Post
    is there anyway to make the cell go a colour and disappear when the user enters data?
    not sure I understand what you want. How does something have a color and disappear at the same time? Maybe if you sent me a workbook that showed how you want it to look when the data has been entered correctly.

  25. #25
    Registered User
    Join Date
    09-13-2009
    Location
    Wales
    MS-Off Ver
    Excel 2003
    Posts
    57

    Re: how to check data has been entered before submitting

    Quote Originally Posted by blane245 View Post
    not sure I understand what you want. How does something have a color and disappear at the same time? Maybe if you sent me a workbook that showed how you want it to look when the data has been entered correctly.
    i will try to explain.

    This code checks which cells should have data, if there is no data it prompts the user to fill in the data in that cell, i would like it to chose the cell (which it does thanks to you) but at the same time i would like it to make that cell a colour so it is "highlighted"

    once they enter data and print again, the colour is no longer there

    make sense?

    thanks

  26. #26
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: how to check data has been entered before submitting

    OK, I've done some stream lining for you since the number of cells to be checked was getting quite large. This code should be easier to handle. Please look at the code in the attached book.

    First, the cells to be validated and the messages are put into arrays. I only did this for the first 3 cells. You will have to add all the others.

    Second, all of the cells to be validated are unhighlighted.

    Then each cell is validate in turn either throwing the error message and canceling the print, or highlighting the cell. Note that highlighting is done by setting the interior fill style and color. Printcheck.xls

  27. #27
    Registered User
    Join Date
    09-13-2009
    Location
    Wales
    MS-Off Ver
    Excel 2003
    Posts
    57

    Re: how to check data has been entered before submitting

    thanks for that, clever stuff

    is there anyway of it highlighting the cell when nothing is entered instead

    as it is, the cell is selected, and when you put text in, and it errors again because of another cell needs completing, it then highlights the completed cell in yellow

    i would prefer it the other way if it is possible, not sure it is. when you press print and no data is entered into the particular cell, it then says for you to complete the cell, selects the cell and highlights it in a colour. once you fill in the data and press print again, it goes past the newley completed cell, removes the colour highlight and prompts and selects the other to be completed cell, this resulting all completed cells with no highlited colours ready for print

    thanks for your effort tho, appreciate it
    Last edited by techmob; 02-09-2010 at 10:03 AM.

  28. #28
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: how to check data has been entered before submitting

    change the call to Highlight to UnHiglight and the call the UnHighlight to Highlight

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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