I am creating userform which I will be using to insert data and then make some other stuff.
I have a Userform with ComboBox and few TextBoxes. ComboBox is filled with data from range. I want to change values of TextBoxes depending on ComboBox value. Values of TextBoxes should be filled with specific values from worksheet. I thought about creating For Each loop to determine Row of chosen ComboBox value and then change TextBoxes using Row number and setting proper offset.
Worksheet is table with headers and filled with data such as name, city etc.
However my code does not work within Userform.
Any ideas what is wrong or maybe a different approach to a problem?
klient = ComboBox name
Private Sub klient_Change()
Dim MyCell As Range, MyRange As Range
Dim wiersz As Long
Set MyRange = Range("klienci")
For Each MyCell In MyRange
If klient.Value = MyCell.Value Then
wiersz = MyCell.Value
Exit For:
End If
Next
MsgBox (wiersz)
End Sub
Klient.List = Range("klienci")
? in that case you could use sth like this to get index of klient from named range:Klient.ListIndex
– Dmitry PavlivUserform_initialize
? – lowakRowSource
is fine:) About your main question you could use this line to get address of selected item of combobox in range:MsgBox Range("klienci").Cells(1 + Klient.ListIndex, 1).Address
(I suppose that your rowSource is exactlyklienci
range) – Dmitry Pavlivklient.Value
to the text box ... otherwise your range must be at least 2 columns wide, you traverse the 1st comumn and return the 2nd column (or so ...)? – MikeDMsgBox Range("klienci").Cells(1 + Klient.ListIndex, 1).Address
was excacly what I was looking for. Now referencing to this cell I can display different values. I modified it for my needs and it's great! Please post an anwser so I can accept it ;) – lowak