Solved

Vb help

Posted on 2011-02-27
9
270 Views
Last Modified: 2012-05-11
Please can you help me alter the code on my workbook.

Basically I would like for the listbox to display the up/down arrows when the userform is opened. So was Textbox1 to equal blank, then the arrows would display along with the listed range.

The picture describes what I would like to achieve but currently I would have to input "A" to achieve this.

Also something weird happens if I type "A" into textbox1 and then press the down arrow on my keyboard and then down again, for some reason it jumps to "Akrotiri" as opposed to descending down the range i.e. "Albania"

Many thanks for your help!

Gary



 help gary-test4.xls
0
Comment
Question by:Gazza83
  • 4
  • 4
9 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 34993265
Hi, see how this goes.  I've made the full list populate when the text box is empty.

The reason the list box was changing is because when an item is selected, it also updates the text box for the selected value, resulting in it being cleared.

I have prevented that, but I don't know how it's going to go with identifying the selection now.

Regards,

Rob.
gary-test4.xls
0
 
LVL 6

Expert Comment

by:TinTombStone
ID: 34993310
Should now start with the listbox loaded
Copy-of-gary-test4.xls
0
 

Author Comment

by:Gazza83
ID: 34993370
Thanks Rob, works well only now the mouse click selection function is disabled.

I was wondering if on selection, the listbox could remain on the value that was last selected.

Something like the attached? help
0
 

Author Comment

by:Gazza83
ID: 34993384
Thanks Tom, I've tried the attached and it works on start up. The only thing is if I hit the down arrow on my keyboard twice, it jumps to Akrotiri as oppposed to moving through the 'drop down'
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 65

Expert Comment

by:RobSampson
ID: 34993526
OK, test this out.  It could be right.  I have removed the TextBox1_Change event, copying the code to a FillListBox sub.  This way, whenever the text box changes due to the list box being selected, it doesn't re-populate the list box.  As for the keystrokes, I've called FillListBox on the KeyUp event of the TextBox, instead of the Change event.

Regards,

Rob.
gary-test4.xls
0
 

Author Comment

by:Gazza83
ID: 34993674
Hi Rob, the code on the file you uploaded works brilliantly, just how I want it. The one problem is that Textbox4 doesn't seem to work:-

the old code had something like:-

End If
    Set rng1 = Sheets("DataSheet").Range("D1:D300").Find(TextBox1.Value, , xlValues, xlWhole)
    If Not rng1 Is Nothing Then TextBox4.Value = rng1.Offset(0, 1)
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 34993751
Ah, change this:
Private Sub ListBox1_Change()
    On Error Resume Next
    If ListBox1.ListIndex > -1 Then
        TextBox1.Text = ListBox1.Value
    End If
    On Error GoTo 0
End Sub


to this
Private Sub ListBox1_Change()
    On Error Resume Next
    If ListBox1.ListIndex > -1 Then
        TextBox1.Text = ListBox1.Value
        CheckIfComplete
    End If
    On Error GoTo 0
End Sub


Regards,

Rob.
0
 

Author Closing Comment

by:Gazza83
ID: 34993819
Many thanks for your help!
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 34993827
No problem. Thanks for the grade.

Regards,

Rob.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
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 a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
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 …

895 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

14 Experts available now in Live!

Get 1:1 Help Now