Lookup and User form
Thank you Atishoo
Your code works fine when I try it on a test case, so you know your stuff.
However when I try to incorporate it in my exicting user form code I am not
experienced enough to get it to work.
The code for the OK Button that I ALLREADY have is looping through col A in
sheet 2 and putting the Item 10, 20, 30 or 40 in the first empty cell, so I
do not need THAT function in the additional code. I only need for the
additional code to find the last allready filled cell in col A and then
LOOKING IT UP in sheet 1 and put the appropriate "ProdName" (produktname) and
"Var" (variant) in the same row in col B and col C in sheet 2.
(See the example table for sheet 1 and sheet 2 in my first post).
I am sure this is not complicated for anyone with a certain experience, but
thats obviously not where I am now. But I am certainly willing to learn.
"Atishoo" wrote:
Assuming that you are triggering this with a command button on your user form
and the value is enetered in a combobox on the user form something like this
might work. havent tested this though.
I would be tempeted to name your ranges rather than use ("a:a") though.
Private Sub CommandButton1_Click()
v = userform1.combobox1.value
With Worksheets("Sheet1").Range("a:a")
Set c = .Find(v, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
With Worksheets("sheet2").Range("a:a")
Set d = .Find("", LookIn:=xlValues)
If Not d Is Nothing Then
firstAddress = d.Address
Do
d.Value = c.value
d.Offset(0, 1).Value = c.offset(0,1).value
d.Offset(0, 2).Value = c.offset(0,2).value
Loop While d Is Nothing
End If
End With
Loop While c Is Nothing
End If
End With
End Sub
This should place your results in the first blank cell in column A in sheet 2.
Tell me how you get on.
|