VBA textbox populate base on combobox selection

%3CLINGO-SUB%20id%3D%22lingo-sub-1433057%22%20slang%3D%22en-US%22%3EVBA%20textbox%20populate%20base%20on%20combobox%20selection%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1433057%22%20slang%3D%22en-US%22%3E%3CP%3EPlease%20sir%20i%20wrote%20a%20code%20on%20my%20user%20form%20to%20populate%20a%20text%20box%20based%20on%20combo%20box%20selection%20but%20the%20text%20box%20isn't%20show%20anything.%20this%20is%20the%20code%26nbsp%3B%3C%2FP%3E%3CP%3Eon%20user%20form%20initialize%3A%3C%2FP%3E%3CP%3E%5BCODE%3Dvba%5Ddim%20i%20as%20long%2C%20lastrow%20as%20long%2C%20ws%20as%20worksheet%3C%2FP%3E%3CP%3Eset%20ws%20%3D%20Sheets%20(%22Sheet1%22)%3C%2FP%3E%3CP%3ELastrow%20%3D%20ws.Range(%22A%22%20%26amp%3B%20Rows.count).End(xlup).Row%3C%2FP%3E%3CP%3Efor%20i%20%3D%206%20to%20Lastrow%3C%2FP%3E%3CP%3Eme.combobox1.AddItem%20ws.cells(i%2C%20%22C%22).value%5B%2FCODE%5D%20this%20first%20code%20is%20working%20perfectly.%3C%2FP%3E%3CP%3Efor%20combo%20box_Change%20()%3C%2FP%3E%3CP%3E%5BCODE%3Dvba%5D%3C%2FP%3E%3CP%3Edim%20i%20as%20long%2C%20lastrow%20as%20long%2C%20ws%20as%20worksheet%3C%2FP%3E%3CP%3Eset%20ws%20%3D%20Sheets%20(%22Sheet1%22)%3C%2FP%3E%3CP%3ELastrow%20%3D%20ws.Range(%22A%22%20%26amp%3B%20Rows.count).End(xlup).Row%3C%2FP%3E%3CP%3Efor%20i%20%3D%206%20to%20Lastrow%3C%2FP%3E%3CP%3Eif%20%26nbsp%3Bval(me.combobox1.value)%20%3D%20ws.cells(i%2C%20%22A%22)%20then%3C%2FP%3E%3CP%3Eme.textbox2%20%3D%20ws.cells(i%2C%20%22L%22).value%3C%2FP%3E%3CP%3Eend%20if%3C%2FP%3E%3CP%3Enext%20i%3C%2FP%3E%3CP%3E%5B%2FCODE%5D%26nbsp%3B%3C%2FP%3E%3CP%3Eplease%20help%20out%20if%20there%20is%20a%20way%20or%20anything%20else%20to%20do.%20Thank%20you%20sir.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1433057%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Highlighted
New 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