Sorry but combo boxs again

swst

Board Regular
Joined
Jan 17, 2005
Messages
186
Trying to understand combo boxs

I have created a user form for a simple datalist
Name, Address, City, Post code

Data entry is through a user form with textboxs - This works fine
Private Sub CommandButton1_Click()
Range("A3").Select
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If

Loop Until IsEmpty(ActiveCell) = True

ActiveCell.Value = TextBox1.Value
ActiveCell.Offset(0, 1) = TextBox2.Value
ActiveCell.Offset(0, 2) = TextBox3.Value
ActiveCell.Offset(0, 3) = TextBox4.Value
TextBox1.Value = ""
TextBox2.Value = ""
TextBox3.Value = ""
TextBox4.Value = ""

End Sub

What i am trying to do is the reverse
Ie Have another userform with a combo box which should be a list of the names on the datasheet
On the choice of a name i want the address details to appear in the textboxs on the new user form


Any suggestions
Steve
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Use the Find method to the find the value in the names range. Set a variable to the returned range. After that:

TextBox1.Value = rangevar.Offset(0,1) and so on will update the text boxes.
 
Upvote 0
Hi

The userform has a combobox and 3 textboxes and a command button. Source data is in sheet2 in the range A1:A4 with row 1 as headings.

Code:

this will populate the textboxes when the combobox entry is selected

Private Sub ComboBox1_change()
TextBox1.Text = WorksheetFunction.VLookup(ComboBox1.Value, Range("a2:d4"), 2, False)
TextBox2.Value = WorksheetFunction.VLookup(ComboBox1.Value, Range("a2:d4"), 3, False)
TextBox3.Value = WorksheetFunction.VLookup(ComboBox1.Value, Range("a2:d4"), 4, False)
End Sub

This will close the form
Private Sub CommandButton1_Click()
Unload UserForm1
End Sub

This will fill the combobox
Private Sub UserForm_Initialize()
For Each ce In Sheets("sheet2").Range("a2:a4")
If ce.Value <> "" Then
ComboBox1.AddItem ce.Value
End If
Next ce

End Sub

Tony
 
Upvote 0
Many thanks Tony

The first 2 parts work perfectly

I dont quite understand the last bit. Are you saying that this will automatically pick up any new names I enter on the 1st user form?
If so I would need to adjust the vlookup ranges each time to also include new data.
or am I talking out of my --s

Steve
 
Upvote 0
Steve

Yes. I'm working on the principle that you will call your first form to enter the data, close that form, then open the second. If you want the range to include any additional entries, you can either (a) put in a fixed range for the lookup that will cover any expanded entries, (b) dynamically work out the lookup range in the form (al la find the last row etc) or (c) use a named range which is dynaminally updated whenever a new entry is generated.


Tony
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,431
Members
448,961
Latest member
nzskater

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top