Solved

Excel 2010 userform

Posted on 2012-03-14
8
452 Views
Last Modified: 2012-03-24
Any sheet 1-20 on the attached program is an order taking form. To the right of the sheet is a button for "Inventory Adjustment". This userform has a drop down box for "PRODUCT". Right now you have to scroll down to pick the item needed. How would I change the code, so that the item number could be typed in, and the program would help you find the item in the data base? For instance, if  an "A" was typed, the window would show items that start with "A". If the next letter was "AA" the window would show items starting with "AA", and so on. But would not let you type an item was not in the data base.
FG.xls
0
Comment
Question by:CRHIV
[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
  • 3
8 Comments
 
LVL 14

Expert Comment

by:Zack Barresse
ID: 37723213
Hi there,

You can use something like this in your userform code module...


Private Sub CboProduct_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    Dim wsCheck As Worksheet
    Dim rCheck As Range
    Dim rFilter As Range
    Dim cProd As Range
    Dim sChars As String
    Set wsCheck = ThisWorkbook.Worksheets("INVENTORY")
    Set rCheck = wsCheck.Range("A2", wsCheck.Cells(wsCheck.Rows.Count, 1).End(xlUp))
    Set rFilter = wsCheck.Range("A3", wsCheck.Cells(wsCheck.Rows.Count, 1).End(xlUp))
    sChars = Me.CboProduct.Value
    If sChars = vbNullString Then
        Me.CboProduct.Clear
        For Each cProd In wsCheck.Range("A3", wsCheck.Cells(wsCheck.Rows.Count, 1).End(xlUp))
            With Me.CboProduct
                .AddItem cProd.Value
                .List(.ListCount - 1, 1) = cProd.Offset(0, 3).Value
            End With
            Next cProd
        Exit Sub
    End If
    If KeyCode < 33 Or KeyCode > 126 Then Exit Sub
    rCheck.AutoFilter 1, sChars & "*"
    On Error Resume Next
    Me.CboProduct.Clear
    For Each cProd In rFilter.SpecialCells(xlCellTypeVisible)
        With Me.CboProduct
            .AddItem cProd.Value
            .List(.ListCount - 1, 1) = cProd.Offset(0, 3).Value
        End With
    Next cProd
    wsCheck.AutoFilterMode = False
End Sub


Basically it's using AutoFilter to filter for the characters you entered into the combobox and 1) clearing the combobox, 2) re-populating the combobox with the filtered values.  You should also add this line to a userform close routine (I didn't see one in your file, so just add it to your userform code module)...


Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    ThisWorkbook.Worksheets("INVENTORY").AutoFilterMode = False
End Sub


HTH

Regards,
Zack Barresse
0
 

Author Comment

by:CRHIV
ID: 37724403
Thanks for the code. Can it be altered a bit? When the "Inv Adj" is opened, can the cursor be positioned in the "PRODUCT" field? When a letter is entered, can the drop down box appear with a field of 8 items and the descriptions listed starting with the item of the closest match for the first letter? When you leave the "PRODUCT" field, it needs to pull the other information off of the "INVENTORY" sheet to fill in "BATCH NO", "LOCATION", "CURRENT" count of inventory. The way it is now, if you start typing, there is no look up help. The only way to get look up help is to first open the drop down box. Then even if the item is selected with the mouse, it doesn't populate the other data when you leave the "PRODUCT" field. The only way to get it to populate the other fields is to do it with the original drop down box.
0
 

Author Comment

by:CRHIV
ID: 37724756
Attached is the latest FG.xls with changes you suggested. See if I put them in right.
FG.xls
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

Author Comment

by:CRHIV
ID: 37724763
Thanks,

Chuck
0
 
LVL 14

Accepted Solution

by:
Zack Barresse earned 500 total points
ID: 37725163
Hi Chuck,

Let me try to answer your questions.

When the "Inv Adj" is opened, can the cursor be positioned in the "PRODUCT" field?
Yes.  In the Userform_Initialize() routine, before the "End Sub", add this line of code...
Me.CboProduct.SetFocus

Open in new window


When a letter is entered, can the drop down box appear with a field of 8 items and the descriptions listed starting with the item of the closest match for the first letter?
AFAIK we don't have this type of functionality or latitude.
When you leave the "PRODUCT" field, it needs to pull the other information off of the "INVENTORY" sheet to fill in "BATCH NO", "LOCATION", "CURRENT" count of inventory. The way it is now, if you start typing, there is no look up help. The only way to get look up help is to first open the drop down box. Then even if the item is selected with the mouse, it doesn't populate the other data when you leave the "PRODUCT" field. The only way to get it to populate the other fields is to do it with the original drop down box.
A workaround for that would be to use a ListBox to show the data and have the textbox instead of a combobox where the user can type the data.

Attached is the latest FG.xls with changes you suggested. See if I put them in right.
The only thing I didn't see in the code was the UserForm_QueryClose event, which was toward the end of my post.  You should really have that as you don't want your data on the INVENTORY sheet to stay filtered if someone closes the form, and that code takes off the autofilter.

HTH

Regards,
Zack Barresse
0
 

Author Closing Comment

by:CRHIV
ID: 37758321
Said what I wanted to do could not be done.
0
 
LVL 14

Expert Comment

by:Zack Barresse
ID: 37759945
Huh.  Not that I mind about the points awarded, but some people here *really* do care.  Awarding an "Average" answer because of the software limitations is, well, naive.  I'm more than happy to tell you things you can't do in Excel all day long, but it certainly shouldn't reflect on the poster.  For future reference, since it can be a big deal to people, I would highly recommend you base your point awards based on merit, not what you deem is appropriate based on application limitations in reference to the poster.  Kind of unfair to the posters.  :)

Have a good one,
Zack
0
 

Author Comment

by:CRHIV
ID: 37760720
Sorry. I felt, with my limited programming knowledge, that it could be done. I didn't know how to go about it. Every seemingly impossible question I had ever asked had been answered to a workable solution. Thanks for your help.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

617 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