RED
RED

Reputation: 3

In VBA Excel, code to pass value from userform based on certain criteria

I need some help for a vba code.

Data is on the same worksheet.

I created a userform that contains a combobox and a text box. The values in the combobox are names stored in sheet1.range("A1:A300"). The user enters a phone number in the textbox.

I struggle creating a code where I could pass the textbox value next to the name choosen by the user in the combobox. The textbox value would be stored in column B.

Thanks for the help.

Upvotes: 0

Views: 203

Answers (1)

karma
karma

Reputation: 2009

Maybe something like this ?

Private Sub TextBox1_Change()
Set Rng = Range("A1:A300")
Set c = Rng.Find(ListBox1.Value, lookat:=xlWhole)
c.Offset(0, 1).Value = TextBox1.Value
End Sub

Private Sub UserForm_Initialize()
Set Rng = Range("A1:A300")
ListBox1.List = Application.Transpose(Rng)
End Sub

enter image description here

Upvotes: 2

Related Questions