?
Solved

Managing a users response

Posted on 2013-10-29
8
Medium Priority
?
175 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 

Author Comment

by:Frank Freese
ID: 39609124
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 52

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 1000 total points
ID: 39609127
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
ID: 39609170
OK...I got the number I was looking for so I'll close this question and move onto something else.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Accepted Solution

by:
Steven Harris earned 1000 total points
ID: 39609190
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
 

Author Comment

by:Frank Freese
ID: 39609201
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
ID: 39609216
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
ID: 39609221
thanks to all!
0
 
LVL 18

Expert Comment

by:Steven Harris
ID: 39609241
Happy to help.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
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.

770 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