Solved

Managing a users response

Posted on 2013-10-29
8
132 Views
Last Modified: 2013-10-29
Folks,
In my workbook are many worksheets that show a function or formula for the user. I allow them to change the data so they can see the impact of their data change. The worksheet will be protected to only allow changes to the pieces.

In the attached worksheet, as an example, I have a command button "Enter Answer". The purpose of this is for the user to enter in the name of the most productive employee based upon pieces per hour. If the answer is correct then there will be a response "Correct answer - great job!". If not then the name entered will appear with a response "XXXXXX is not the most productive employee. Try again!"

Since the user can change the number of pieces the most productive employee can also change.

I know how to capture the user  response in VBA. I know that I need to find the Max value from D4:D9. I know I need to match the Max value to the name. I know that if the names do not agree then the user has not entered in the correct name.

Except for capturing the user response I do not know how to code the rest.
MostProductive.xlsm
0
Comment
Question by:Frank Freese
  • 5
  • 2
8 Comments
 

Author Comment

by:Frank Freese
Comment Utility
Let me break this question down into several questions to begin with since I can see that happening. Here's code that I have tried just to get the Max from a range:
Private Sub cmdIdentifyMostProductive_Click()
Dim MaxRange As Range
Dim MaxAnswer As Double
Set MaxRange = Worksheets("Production Per Hour").Range("D4:D9")
MaxAnswer = Application.WorksheetFunction.Max(MaxRange)
End Sub

Open in new window


What I am trying to do is simply get the Max value from the range D4:D9 and assign it to MaxAnswer. This code only returns a zero. So if you all do not mind, let's start here first. Once this has been resolved I'll open the next question.
0
 
LVL 48

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 250 total points
Comment Utility
Hi,

as a formula
=INDEX(A4:A9,MATCH(MAX(D4:D9),D4:D9,0))

Open in new window

in VBA
Result = WorksheetFunction.Index(Range("A4:A9"), WorksheetFunction.Match(WorksheetFunction.Max(Range("D4:D9")), Range("D4:D9"), 0))

Open in new window

and then compare the result with the response
if Result = Response then
    MsgBox "You're right"
Else
    MsgBox " You're wrong. Please retry!"
End If

Open in new window


Regards
0
 

Author Comment

by:Frank Freese
Comment Utility
OK...I got the number I was looking for so I'll close this question and move onto something else.
0
 
LVL 18

Accepted Solution

by:
Steven Harris earned 250 total points
Comment Utility
I came up with the same as Rgonzo:

Private Sub cmdIdentifyMostProductive_Click()
    Dim mName As String
    Dim uName As String
    
    uName = Application.InputBox("Enter Answer", "MOST PRODUCTIVE EMPLOYEE", Type:=2)
        
    mName = WorksheetFunction.Index(Range("A4:A9"), _
        WorksheetFunction.Match(WorksheetFunction.max(Range("D4:D9")), _
        Range("D4:D9"), 0))
            
    If uName <> mName Then
        MsgBox mName & " is the most productive employee.  Try Again!"
    Else
        MsgBox "Correct Answer - great job!"
    End If
End Sub

Open in new window


Functioning Example is attached.
MostProductive.xlsm
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:Frank Freese
Comment Utility
Rgonzo1971,
Just saw your response. let me try that now.
I'm having a problem reading your VBA code. Could you post it like I would write it please?
0
 

Author Comment

by:Frank Freese
Comment Utility
WOW! I'm getting exactly the response neede from your posts.
Great job folks looks like 50/50 and greatly appreciated
0
 

Author Closing Comment

by:Frank Freese
Comment Utility
thanks to all!
0
 
LVL 18

Expert Comment

by:Steven Harris
Comment Utility
Happy to help.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

What is a Form List Box? (skip if you know this) The forms List Box is the alternative to the ActiveX list box. If you are using excel 2007, you first make sure you have a developer tab (click the Orb)->"Excel Options"->Popular->"Show Developer tab…
INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now