Solved

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

Posted on 2014-09-23
12
73 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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
 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

815 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

11 Experts available now in Live!

Get 1:1 Help Now