VBA Textbox populate base on combobox selection

Abusalma02

New Member
Joined
Feb 29, 2020
Messages
17
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
  2. Web
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:
VBA Code:
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
this first code is working perfectly.
for combo box_Change ()
VBA Code:
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
please help out if there is a way or anything else to do. Thank you sir.
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hi & welcome to MrExcel.
Change you Initialize event code to
VBA Code:
   With Sheets("Sheet1")
      Me.ComboBox1.List = .Range("C6:C" & .Range("A" & Rows.Count).End(xlUp).Row).Value
   End With
for populating the combo, & then use this
VBA Code:
Private Sub ComboBox1_Click()
   Me.TextBox1.Value = Sheets("Sheet1").Range("L" & Me.ComboBox1.ListIndex + 6).Value
End Sub
to populate the textbox.
 
Upvote 0
Hi & welcome to MrExcel.
Change you Initialize event code to
VBA Code:
   With Sheets("Sheet1")
      Me.ComboBox1.List = .Range("C6:C" & .Range("A" & Rows.Count).End(xlUp).Row).Value
   End With
for populating the combo, & then use this
VBA Code:
Private Sub ComboBox1_Click()
   Me.TextBox1.Value = Sheets("Sheet1").Range("L" & Me.ComboBox1.ListIndex + 6).Value
End Sub
to populate the textbox.

This is fantastic Mr. Excel Thank you sir.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,921
Messages
6,122,280
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top