Consulting

Results 1 to 6 of 6

Thread: Solved: Validating Excel data entry

  1. #1
    VBAX Regular
    Joined
    May 2008
    Posts
    21
    Location

    Solved: Validating Excel data entry

    I have a spreadsheet into which staff are required to enter information. Some information must be entered, and where values are entered, other information must also be entered.

    So, for example, I have the following:

    In Columns A -> I I have the following headings:

    Serial Num
    Removed (Y/N)
    Num Removed
    Unit Cost
    Removed By
    Date Removed
    Num Left
    Reordered (Y/N)
    Date Reordered

    Staff would enter the serial number, and if a 'Y' is entered in column B, they must enter a value in Column C.

    Similarly, if a 'Y' is entered in Column H, a value must be entered in Column I.

    What I want to know is, without the use of a data entry form, is it possible to incorporate this kind of error checking in an Excel spreadsheet? Is it also possible to code it so that cells are greyed out if they are not required, coloured if they are, and flagged if they need an entry?

    Duncs

  2. #2
    VBAX Expert
    Joined
    Aug 2007
    Location
    Windermere, FL, a 'burb in the greater Orlando metro area.
    Posts
    567
    Location
    Duncs,

    Perhaps you can get some ideas from the attached file. I used data validation to control the answers used in col B and H, and conditional formatting to color code exceptions in columns B and H (missing entry) and C and I (not needed, missing entry, entry without related Y/N answer). You can adjust colors and logic as required.

    Cheers!
    Ron
    Windermere, FL

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    You can add code to prevent closing unless cells are filled.
    Based on Ron's example

    [VBA]
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Dim Rng As Range
    Dim MyAdd As String
    Set Rng = Union(Intersect(Columns(2), ActiveSheet.UsedRange), Intersect(Columns(8), ActiveSheet.UsedRange))
    For Each cel In Rng
    If cel = "Y" And cel.Offset(, 1) = "" Then
    MyAdd = MyAdd & cel.Offset(, 1).Address(0, 0) & vbCr
    End If
    Next
    If Len(MyAdd) > 1 Then
    Cancel = True
    MsgBox "Enter data in cells" & vbCr & MyAdd
    End If
    End Sub
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    VBAX Expert
    Joined
    Aug 2007
    Location
    Windermere, FL, a 'burb in the greater Orlando metro area.
    Posts
    567
    Location
    And, based on Malcolm's code, you can also alert the user to two other cases that need correction (a No entry with data following and a data cell with neither a Yes or No answer preceding).

    Cheers!
    Ron
    Windermere, FL

  5. #5
    VBAX Regular
    Joined
    May 2008
    Posts
    21
    Location
    Many thanks for your replies. I think I was trying to over-complicate matters, looking at alerts if the field is blank etc. Conditional formatting does the job just as good.

    Cheers

    Duncs

  6. #6
    VBAX Expert
    Joined
    Aug 2007
    Location
    Windermere, FL, a 'burb in the greater Orlando metro area.
    Posts
    567
    Location
    Glad to be able to help.

    Cheers!
    Ron
    Windermere, FL

Posting Permissions

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