VBA textbox populate base on combobox selection

Copper Contributor

Please sir i wrote a code on my user form to populate a text box based on combo box selection but the text box isn't show anything. this is the code 

on user form initialize:

[CODE=vba]dim i as long, lastrow as long, ws as worksheet

set ws = Sheets ("Sheet1")

Lastrow = ws.Range("A" & Rows.count).End(xlup).Row

for i = 6 to Lastrow

me.combobox1.AddItem ws.cells(i, "C").value[/CODE] this first code is working perfectly.

for combo box_Change ()

[CODE=vba]

dim i as long, lastrow as long, ws as worksheet

set ws = Sheets ("Sheet1")

Lastrow = ws.Range("A" & Rows.count).End(xlup).Row

for i = 6 to Lastrow

if  val(me.combobox1.value) = ws.cells(i, "A") then

me.textbox2 = ws.cells(i, "L").value

end if

next i

[/CODE] 

please help out if there is a way or anything else to do. Thank you sir.

0 Replies