Case WorksheetFunction problem

Folks,
In the WorksheetChange event I am using the following code to verify a correct answer for a function, Mode.Sngl:
Private Sub Worksheet_Change(ByVal Target As Range)
 Application.EnableEvents = False
 On Error GoTo ErrorRoutine
 Select Case True
 Case Range("P7").Value = ""
 'The user hasn't given an answer so just clear any messaage that might be in P7
    Range("P7").Value = ""
    'We know at this point that there's something in P7 so se if it is the right answer
 Case WorksheetFunction.ModeSngl(Range("N6:N15")) = Range("P7").Value
 'Correct answer but see if he used a formula
 If InStr(1, Range("P7").Formula, "MODE.SNGL", vbTextCompare) > 0 Then
    Range("Q7").Value = "Correct"
 Else
    Range("Q7").Value = "Correct but please use the MODE.SNGL function"
 End If
 Case WorksheetFunction.ModeSngl(Range("N6:N15")) <> Range("P7").Value
    'Incorrect answer
    Range("Q7").Value = "Incorrect"
    Case Else
        Range("Q7").Value = "Incorrect"
  End Select
  Application.EnableEvents = True
  Exit Sub
ErrorRoutine:
 Range("Q7").Value = Range("Q7").Text & " Error - read Remarks"
 Application.EnableEvents = True
End Sub

Open in new window

The problem I am having is at line 9:
Case WorksheetFunction.ModeSngl(Range("N6:N15")) = Range("P7").Value
The function is Mode.Sngl, however, when I enter that instead of ModeSngl I get the following compile error:
mode-error.jpgI do not know of a solution since I will have other functions similar to the one above.
Frank FreeseAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

als315Commented:
Screenshot shows mistype:
WorksheetFunction.Mode.Sngl
instead of
WorksheetFunction.ModeSngl
0
Frank FreeseAuthor Commented:
OK...I found the error. It should be Mode_Sngl. Great! However, I'm not getting the results from line 11 as being "Correct"
0
FamousMortimerCommented:
Hi,
You can use WorksheetFunction.Mode_Sngl(Range("N6:N15"))

Just keep in mind that it will throw an Application Error if the range does not have a mode average so you will have to handle it if that is a possibility
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

FamousMortimerCommented:
To help debug and find the cause add this line before Case WorksheetFunction.ModeSngl(Range("N6:N15")) = Range("P7").Value

MsgBox "Is " & WorksheetFunction.Mode_Sngl(Range("N6:N15")) & " equal to " & Range("P7").Value & "?"

Open in new window

0
Frank FreeseAuthor Commented:
OK...this is on my laptop and I'm creating a monthly image now. Will get back later
0
Martin LissOlder than dirtCommented:
Here is corrected code.

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
 On Error GoTo ErrorRoutine
 Select Case True
    Case Range("P7").Value = ""
    'The user hasn't given an answer so just clear any messaage that might be in P7
        Range("P7").Value = ""
       'We know at this point that there's something in P7 so se if it is the right answer
    Case WorksheetFunction.Mode_Sngl(Range("N6:N15")) = Range("P7").Value
        'Correct answer but see if he used a formula
        If InStr(1, Range("P7").Formula, "MODE.SNGL", vbTextCompare) > 0 Then
           Range("Q7").Value = "Correct"
        Else
           Range("Q7").Value = "Correct but please use the MODE.SNGL function"
        End If
    Case WorksheetFunction.Mode_Sngl(Range("N6:N15")) <> Range("P7").Value
       'Incorrect answer
       Range("Q7").Value = "Incorrect"
       Case Else
           Range("Q7").Value = "Incorrect"
  End Select
  Application.EnableEvents = True
  Exit Sub
ErrorRoutine:
 Range("Q7").Value = Range("Q7").Text & " Error - read Remarks"
 Application.EnableEvents = True
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Frank FreeseAuthor Commented:
thanks folks
appreciate the code change Martin
0
Martin LissOlder than dirtCommented:
You're welcome.
0
Frank FreeseAuthor Commented:
I've been chipping away at those Statistical worksheets where there was a single result, such as AVERAGE. That just leaves figuring out how to evaluate those worksheets with multiple results, such as AVERAGEA or PERCENTILE but that's another question.
BTW, no feedback on the Consolidated project, at all.
0
Martin LissOlder than dirtCommented:
No news is good news.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.