Consulting

Results 1 to 15 of 15

Thread: Counting DataValidation Attempts

  1. #1
    VBAX Tutor
    Joined
    Jun 2012
    Posts
    240
    Location

    Counting DataValidation Attempts

    Counting the number of times a person enters something a cell with data validation before entering a valid entry:

    I have a list of cells, each with a different data validation list (single characters) based on the character in the cell next to it. I want to count the number of attempts for each cell until a correct entry is made. This is so that I can develop a score for the person trying to type the correct value into the cells. It is a young kid who is still getting used to the keyboard and I want to make learning the keyboard a bit more fun by putting a score to it.

    I hope this is possible

    Thank you so much!
    Best Regards
    Vanhunk
    Last edited by Aussiebear; 05-03-2023 at 03:47 AM. Reason: Reduced the font size so no one is "Shouting"

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,727
    Location
    Crude, but might give you some ideas.

    Option Explicit
    
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim r As Range
        Dim s As Variant
        Set r = Target.Cells(1, 1)
        If Intersect(r, Range("A2:A4")) Is Nothing Then Exit Sub
        s = r.Offset(0, 1).Value
        If r.Value <> s Then
            n = n + 1
            MsgBox "Wrong answer, that's " & n
            r.Select
        Else
            MsgBox "Good job, try another one"
            n = 0
        End If
    End Sub
    Attached Files Attached Files
    Last edited by Aussiebear; 05-01-2023 at 12:06 PM. Reason: Added code from Workbook
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Tutor
    Joined
    Jun 2012
    Posts
    240
    Location
    Hi Paul

    Thank you very much, I am sure I can adapt it for my purposes. I will post the final once I have figured it out.

    Best Regards
    Vanhunk

  4. #4
    you may also try to check the Cell.Validation
    Attached Files Attached Files

  5. #5
    VBAX Tutor
    Joined
    Jun 2012
    Posts
    240
    Location
    Thank you Arnelgp

    I love it!

    Regards
    Vanhunk

  6. #6
    VBAX Tutor
    Joined
    Jun 2012
    Posts
    240
    Location

    Counting Data Validation Attempts

    Dear all

    I have attached an example of the file that I want to use.

    Note that each cell in the named "yellow" ranges has its own data validation, a list with one character and no drop-down.

    I would like to score the person completing the cells and have the score written on the sheet. For each correct first attempt I want to add 2 to the score and with each wrong attempt subtract 1 from the score.

    I believe some combination of Paul_Hossler's code and that of Arnelgp would do the trick, I could however not work it out.

    I was thinking something like a combination of
     If Target.Value = Target.Validation.Value Then
    and
     Intersect
    with
     Private Sub Worksheet_Change(ByVal Target As Range) 
    would work. I could unfortunately not figure out the how.

    Any further assistance is much appreciated.

    Regards
    Vanhunk
    Attached Files Attached Files

  7. #7
    check if the Score is correct.
    Attached Files Attached Files

  8. #8
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    Very nicely done arnelgp.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  9. #9
    VBAX Tutor
    Joined
    Jun 2012
    Posts
    240
    Location
    Thank you arnelgp, much appreciated

    Yes, the score is correct, but also not. I would like to subtract 1 for each incorrect attempt. The way it is set up is that you can't go further without putting in the correct character, thus without subtracting the incorrect attempts you will always get a full score. I believe that is the most challenging part.

    I agree with Aussiebear, very nicely done. Now for the final challenge.

    Best Regards
    Vanhunk

  10. #10
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    So, what happens if they continue to put in a wrong selection, do we continue to add 1 to the score?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  11. #11
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,198
    Location
    How about the attached?
    Attached Files Attached Files
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  12. #12
    VBAX Tutor
    Joined
    Jun 2012
    Posts
    240
    Location
    Aussiebear

    As long as they enter the incorrect value, i.e. press enter or the arrow key (which will cause an error message), 1 must be subtracted from the score. When the correct character is finally entered, 1 must be added to the score.

  13. #13
    VBAX Tutor
    Joined
    Jun 2012
    Posts
    240
    Location
    Good day georgiboy

    You have nailed it, it is doing exactly as I intended it to work!

    Thank you guys I really appreciate all your effort and I think the result is brilliant!

    Best Regards
    Vanhunk

  14. #14
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,198
    Location
    You are very welcome, we are always happy to help here.
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  15. #15
    alright.
    Last edited by arnelgp; 05-12-2023 at 06:53 PM.

Tags for this Thread

Posting Permissions

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