Combobox to label / textbox

SPLUCENA

Board Regular
Joined
Feb 24, 2009
Messages
189
Hi All,

I placed a combobox to my useform where the data for my dropdown list are based in excel. I have also put around 10 label/ textbox on the userform. Kindly help me write the code that when I chose row 1 in my list (excel) thru the combo box the labels will be populated with the corresponding datas along the row.

Ex.

Combobox label1 label2 label3 ......
engine a1 a2 a3 .......

thanks for the usual assistance

splucena
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

dialup

Board Regular
Joined
Jan 10, 2008
Messages
99
not tested this but i think you are looking for something like

Code:
private sub combobox1_afterupdate()
if combobox1.text="your first line from list here" then
label1.caption="what you want "
label2.caption="what you want"
end if
if combobox1.text="your second line from list here" then
label1.caption="what you want "
label2.caption="what you want"
end if
end sub

should put you on the right tracks
 

SPLUCENA

Board Regular
Joined
Feb 24, 2009
Messages
189
Hi Dial Up,

I tried your code but it is not what I want to be. What I really mean is I have around 100 items of product to choose from in the combobox, where the list for the combobox lies in sheet1 of excel. along with the product list are the corresponding details on the next column with the same row. there are around 10 columns as product description. What I want is if I choose product 1 on column A and on first row (thru combobox) the 10 labels I attached to the userform will show the datas from column B,C,D..... of the same row and so on with as assigned on the different labels, and so the loop will go if I choose column A row 2, the datas on row 2 Column B,C,D,.... will reflect on the labels as its caption. I have a code in mind but just can't figure how to write it right.

Thanks for the help!


splucena
 

Chris Bode

Board Regular
Joined
Jan 25, 2009
Messages
103
Hope following code will make some sense...
Code:
Private Sub ComboBox1_Change()
    Dim row As Integer
    row = CInt(ComboBox1.Text)
    
    Label1.Caption = Sheet1.Cells(row, 1).Value
    Label2.Caption = Sheet1.Cells(row, 2).Value
End Sub

Private Sub UserForm_Click()
   
    ComboBox1.AddItem ("1")
    ComboBox1.AddItem ("2")
End Sub
 
L

Legacy 68668

Guest

ADVERTISEMENT

try
Code:
Private Sub ComboBox1_Click()
Dim x As Long
x =  ComboBox1.ListIndex
If x > -1 Then
    For i = 1 To 10
        Me.Controls("Lable" & i).Caption = Sheets("Sheet1").Cells(x, i + 1).Value
    Next
End If
End Sub
Alter Sheet1 to the actual sheet name
 

SPLUCENA

Board Regular
Joined
Feb 24, 2009
Messages
189
Hi Guys,


Thanks for the codes. I'll try it later. However I have tried this code and it is working just fine.

Dim mycl As Range
Application.ScreenUpdating = False
Application.EnableEvents = False
On Error Resume Next
Set mycl = Sheets("1L").Cells.Find(ComboBox1.Value) 'search whole sheet (.cells)
ComboBox1.Value = mycl.Value
Label2.Caption = mycl.EntireRow.Range("B1").Value & vbCr
Label4.Caption = mycl.EntireRow.Range("C1").Value & vbCr
Label8.Caption = mycl.EntireRow.Range("D1").Value & vbCr
Label11.Caption = mycl.EntireRow.Range("E1").Value & vbCr
Label12.Caption = mycl.EntireRow.Range("AA1").Value & vbCr
Label14.Caption = mycl.EntireRow.Range("J1").Value & vbCr
Label17.Caption = mycl.EntireRow.Range("K1").Value & vbCr
Label19.Caption = mycl.EntireRow.Range("L1").Value & vbCr
Label21.Caption = mycl.EntireRow.Range("U1").Value & vbCr
Label23.Caption = mycl.EntireRow.Range("V1").Value & vbCr
Label25.Caption = mycl.EntireRow.Range("W1").Value & vbCr
Label27.Caption = mycl.EntireRow.Range("G1").Value & vbCr
Label28.Caption = mycl.EntireRow.Range("H1").Value & vbCr
Label30.Caption = mycl.EntireRow.Range("M1").Value & vbCr
Label31.Caption = mycl.EntireRow.Range("N1").Value & vbCr
Label33.Caption = mycl.EntireRow.Range("X1").Value & vbCr
Label34.Caption = mycl.EntireRow.Range("Y1").Value & vbCr
Set mycl = Nothing
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
 

SPLUCENA

Board Regular
Joined
Feb 24, 2009
Messages
189
Hi Guys,

I want to link an image to my combobox, how will I do it without loosing the data of the combobox from its original list source? I was provided with a code earlier but combobox list source was changed into photo list / directory thus loosing datas I want to show up in label caption. Kindly assist.


thnks,

splucena
 

Watch MrExcel Video

Forum statistics

Threads
1,130,310
Messages
5,641,450
Members
417,210
Latest member
rins

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
Top