Hello
I am a VB noob and i am trying to help my non-tech savvy colleagues in a rural non-profit to maintain better data.
I am sure there are better ways of data maintenance, but they are used to one way of working over the years and I need to align the excel to match their way of doing things.
They maintain user data with static details (like name, village, occupation, etc.) and dynamic details (service taken, etc.) in the same sheet. Problem is, due to manual entry, the static fields become erroneous.
So what I want to achieve in the userform is:
1. If he is new user, he signs up separately.
2. If old user, he chooses his name in a dropdown list.
3. User details (static ones) are shown in a listbox. Since there are multiple people with exactly the same name, he chooses which details match him.
4. These details are passed on to the form and he adds the dynamic details.
I have done everything, the only two areas where I am blocked are:
1. How to lookup the values in the excel and display in a multi-column textbox ONLY with the unique combinations. Presently, i am populating a list, but its showing all values and also, i cannot use that for point 2 below. I need a better way.
2. How to carryover the values to the other userform from the list box (I think I will be able to figure this point out myself if the first problem is resolved)
I am attaching the sheet with some dummy values for your reference.
Would it be possible to help? Let me know if I have not been able to convey the issue clearly.
Copy of Data tool.zipCopy of Data tool.zip
hi shuvajit, welcome to Excelforum, re 1 problem area:
1. How to lookup ...
Check attachment.
I have made some changes to Initializing code as well.
Hello shuvajit,
Welcome to the Forum!
This should get you started. Now when you select a user's name from the CombBox, a unique list of names is produced in the ListBox. Here is the UserForm code. The attached workbook has all the changes.
Public Dic As Object Private Sub ComboBox1_Click() Dim Data As Variant Dim I As Long, J As Long Dim R As Long Dim Users As Collection If ComboBox1.ListIndex = -1 Then Exit Sub Data = Dic(ComboBox1.Value) Data = Split(Data, ",") ListBox1.Clear ListBox1.ColumnCount = 6 Set Users = New Collection For I = 0 To UBound(Data) Set Rng = Cells(Data(I), "C").Resize(ColumnSize:=5) User = WorksheetFunction.Index(Rng.Value, 1, 0) User = Application.Trim(Join(User, " ")) On Error Resume Next Users.Add 1, User If Err = 0 Then ListBox1.AddItem For J = 0 To 4 ListBox1.List(ListBox1.ListCount - 1, J) = Rng.Cells(I + 1, J + 1) Next J End If On Error GoTo 0 Next I End Sub Private Sub CommandButton2_Click() UserForm1.Hide Unload Me UserForm2.Show End Sub Private Sub CommandOk_Click() UserForm1.Hide Unload Me UserForm2.Show End Sub Private Sub UserForm_Initialize() Dim Cell As Range Dim Data As Variant Dim I As Long Dim Item As String Dim Key As Variant Dim Rng As Range Dim LastRow As Long LastRow = Cells(Rows.Count, "B").End(xlUp).Row Set Rng = Range("B2:B" & LastRow) R = Rng.Row Data = Rng.Value Set Dic = CreateObject("Scripting.Dictionary") Dic.CompareMode = vbTextCompare For I = 1 To UBound(Data) Key = Trim(Data(I, 1)) If Key <> "" Then Item = R + I - 1 If Not Dic.Exists(Key) Then Dic.Add Key, Item Else Item = Dic(Key) & "," & Item Dic(Key) = Item End If End If Next I ComboBox1.List = Dic.Keys End Sub
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Hello
Thanks for the help... The files work just as i want them to ...
I am going by Leith's file, because it seems, having the values as separate columns will allow me to carry over the values to the next sheet easily.
Thanks a lot again.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks