Dear forum Members!
First of all, I apologize for my poor English. Not my native language...
I would like to ask you for help in solving a complex problem.
I have a Userform that has three OptionButtons, three TextBoxes, and one ComboBox element.
What I want to achieve is that when I select OptionButton1, it lists the table1 elements of Sheet1 as its ComboBox elements.
If I select OptionButton2, it lists the table2 elements of Sheet2 as its ComboBox elements.
And when I select OptionButton3, it lists the table3 elements of Sheet3 as its ComboBox elements.
- I would like the Combobox elements to not contain empty lines, so exclude them so that they cannot be selected.
- I should be able to type something into the ComboBox, not just select it.
- If I select something from the ComboBox elements, it reads the values of the table from the appropriate table (which is in one line) and automatically enters them as the values of TextBox1, TextBox2, TextBox3. Textboxes are located inside the Userform (where the ComboBox is).
- If I delete the name, delete the contents of the TextBoxes.
- I don't want to tie the filling of the TextBoxes to a button.
- None of the three OptionButtons is checked by default. It is up to the user to choose which one they want. When an OptionButton is selected, the previously hidden ComboBox and TextBoxes appear. I think this makes the solution easier.
- On each worksheet, the table values start with row A2 and are 4 columns wide. The first line is the header line.
- The three worksheets are in one workbook.
Do you think this is feasible?
Currently, these two codes are in operation, but they are mutually exclusive and the possibility of expansion.
Thank you in advance for your help!
First of all, I apologize for my poor English. Not my native language...
I would like to ask you for help in solving a complex problem.
I have a Userform that has three OptionButtons, three TextBoxes, and one ComboBox element.
What I want to achieve is that when I select OptionButton1, it lists the table1 elements of Sheet1 as its ComboBox elements.
If I select OptionButton2, it lists the table2 elements of Sheet2 as its ComboBox elements.
And when I select OptionButton3, it lists the table3 elements of Sheet3 as its ComboBox elements.
- I would like the Combobox elements to not contain empty lines, so exclude them so that they cannot be selected.
- I should be able to type something into the ComboBox, not just select it.
- If I select something from the ComboBox elements, it reads the values of the table from the appropriate table (which is in one line) and automatically enters them as the values of TextBox1, TextBox2, TextBox3. Textboxes are located inside the Userform (where the ComboBox is).
- If I delete the name, delete the contents of the TextBoxes.
- I don't want to tie the filling of the TextBoxes to a button.
- None of the three OptionButtons is checked by default. It is up to the user to choose which one they want. When an OptionButton is selected, the previously hidden ComboBox and TextBoxes appear. I think this makes the solution easier.
- On each worksheet, the table values start with row A2 and are 4 columns wide. The first line is the header line.
- The three worksheets are in one workbook.
Do you think this is feasible?
Currently, these two codes are in operation, but they are mutually exclusive and the possibility of expansion.
Thank you in advance for your help!
VBA Code:
Private Sub Userform_Initialize()
Dim LastRow As Long
Dim Cella As Range
Dim WSL As Worksheet
Set WSL = Worksheets("Sheet1")
With WSL
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For Each Cella In .Range("A2:A" & LastRow)
If Cella.Value <> "" Then
Me.ComboBox_Name.AddItem Cella.Value
End If
Next
End With
End Sub
Private Sub ComboBox_Name_Afterupdate()
Dim Search As String
Dim FoundCell As Range, SearchRange As Range
Dim WS As Worksheet
Set WS = Worksheets("Sheet1")
Set SearchRange = WS.Range("A1", WS.Range("D10").End(xlUp))
Search = Me.ComboBox_Name.Text
If Len(Search) = 0 Then Exit Sub
Set FoundCell = SearchRange.Find(What:=Search, LookIn:=xlValues, LookAt:=xlWhole)
If Not FoundCell Is Nothing Then
Me.TextBox_PostCode.Value = FoundCell.Offset(0, 1).Value
Me.TextBox_City.Value = FoundCell.Offset(0, 2).Value
Me.TextBox_Street.Value = FoundCell.Offset(0, 3).Value
Else
Me.TextBox_PostCode.Text = ""
Me.TextBox_City.Text = ""
Me.TextBox_Street.Text = ""
End If
End Sub