Solved

If JRY selected from Picklist then a input box will appear. Entry stored on seperate sheet

Posted on 2014-09-23
12
70 Views
Last Modified: 2014-10-02
I have a pick list of various codes, when user selects only JRY I would like an input box to come up requesting user input "Jury ID", the value would be stored on a seperate sheet along with a Date and Employee Needing Coverage name from the same line were JRY appears. This is a form so JRY could appear 2 - 3 times in a month on any line in the range of C15 - C84. .  There are various other codes in the picklist but only "JRY" will trigger the input box, then when inputed box would go away. User would remain on "Form" sheet.
Expert-Echange-image.jpg
0
Comment
Question by:Walter Williams
  • 6
  • 6
12 Comments
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40340344
It should be possible to set up a Worksheet_Change event to capture something like this, but there is an issue with the process.

As I was replicating the example workbook, I note that it's quite possible that the JRY replacement code will be selected BEFORE the name for the Employee Needing Coverage is entered (since most western forms tend to enter data from left to right).  This causes a problem:  if JRY is selected before the Date and/or Employee Needing Coverage fields are complete, no data can be copied to the separate Jury data sheet.

If a process were to wait for all three values to be complete, then the additional message box wouldn't appear until after the last value was complete.

How would you expect this to behave?

-Glenn
0
 

Author Comment

by:Walter Williams
ID: 40340371
Glenn,

You bring up a great point, thanks for the question..  For a quick fix, I have moved column C "Replacement Code" to far right between column G and G is now H. This would make selecting JRY one of the last fields they should select.  I am working on trying to force an order of entry to insure Date, Employee Needing Coverage and Replacement Code are filled out first in that order.
0
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40340403
That would work.  Additionally, some extra control in a Worksheet_Change event could prevent a selection of a Replacement Code unless the Date and Employee Needing Coverage fields were complete (not blank) for that row.

I'll see what I can whip up.

-Glenn
0
 

Author Comment

by:Walter Williams
ID: 40340455
ok, thank you very very much...
0
 

Author Comment

by:Walter Williams
ID: 40350417
Hi Glenn,

Just checking back to see if you had any luck? Were you able to come up with anything.

Thank you..
0
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40350497
Sorry; I knew I forgot to check on something over the weekend.  I'll take a look at this and post back shortly.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:Walter Williams
ID: 40350686
lol..  Thanks Glenn, much appreciated...
0
 
LVL 27

Accepted Solution

by:
Glenn Ray earned 500 total points
ID: 40351160
Sorry this took so long.  I ran into a technical issue with Excel that I couldn't resolve (and may have to post my own question here @ EE if I can't find an explanation).  But, I created a workaround that behaves almost exactly the same.

There is a Worksheet_Change event that checks the value for the Replacement Code; if "JRY", an dialog box appears prompting for a required Jury ID.
Option Explicit
Dim rng As Range
Dim cl As Object
Dim strJuryID, strEmpNeed As String
Dim dtReqDate As Date
Dim r As Integer
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("$G$15:$G$84")) Is Nothing Then
        If Target.Value <> "" And _
            ((Target.Offset(0, -6) = "") Or (Target.Offset(0, -3) = "")) Then
            Target.Value = ""
            MsgBox "Please complete previous fields before" & vbLf & _
                   "selecting a replacement code.", vbExclamation + vbOKOnly, "Additional Data Required"
        ElseIf Target.Value = "JRY" Then
            frmJuryID.Show
            strJuryID = frmJuryID.txtJuryID
            dtReqDate = Target.Offset(0, -6).Value
            strEmpNeed = Target.Offset(0, -3).Value
            'determine if this data already exists, if so, do not update
                Set rng = Sheets("JuryData").Range("A2", Sheets("JuryData").Range("A20000").End(xlUp))
                For Each cl In rng
                    If (cl.Value = dtReqDate) And (cl.Offset(0, 1).Value = strEmpNeed) And _
                       (cl.Offset(0, 2).Text = strJuryID) Then
                       Exit Sub  'because line already exists
                    End If
                Next cl
            
            'otherwise locate last available row
            r = Sheets("JuryData").Range("A20000").End(xlUp).Offset(1, 0).Row
            With Sheets("JuryData")
                .Cells(r, 1) = dtReqDate
                .Cells(r, 2) = strEmpNeed
                .Cells(r, 3) = strJuryID
            End With
        End If
    End If
End Sub

Open in new window


If no value is supplied, the data is not duplicated to the separate "JuryData" sheet.  The code checks to see if an entry with the same date, name, and jury ID already exists.  If so, nothing happens; otherwise, the values are added to the table.  It DOES NOT CHECK or handle any processing if the values are changed or deleted on the main sheet; that is a significant addition in work with all the possible variable changes.

See the attached workbook for an example.

-Glenn
EE-Q-28524097.xlsm
0
 

Author Comment

by:Walter Williams
ID: 40352952
Hey Glenn,  

This is awesome.. you the man!!  very impressed..     It is doing exactly what I wanted it to do..

The form will be recycled each month so basically everything deleted in the fields and re filled out for the next month. I get an error when I try to delete what is currently on the form and it throws me into a run-time error screen.   Any suggestions. I have attached the final file so you can see how it works.
Central-Staffing-Request-Template-Master
0
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40356359
Add this line of code to the top of the Worksheet_Change event (in the "Form" sheet object in VBA)
If Target.Rows.Count > 1 Or Target.Columns.Count > 1 Then Exit Sub

Open in new window


before
If Not Intersect(Target, Range("$G$15:$G$324")) Is Nothing Then

This will avoid the JRY check if you select multiple cells to delete.

-Glenn
0
 

Author Closing Comment

by:Walter Williams
ID: 40357527
Perfect...   That did it....   Thank you again this is awesome and exactly what I was needing.
0
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40357716
You're welcome.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

760 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

21 Experts available now in Live!

Get 1:1 Help Now