1.11M Members

combo box and textbox

 
0
 

in sheet1, i have a table like this

 activities                  date completed

 drawing                     jan.1,2013
 painting                    jan.6,2013

(note:this table is downloaded from web,everytime the value on the web changes,the value in the excel spreadsheet also changes.)

then, i have a form . it is composed with a combo box and a textbox.
i was able to populate the combobox with the item on the activities column.

what i want is that whenever i click the drawing in the combobox, i want the textbox to display the date completed corresponding to this item which is "jan.1,2013".

i dont know what to do.im stuck in here.

here's my code:

Private Sub UserForm_Initialize()
'Populate Activities combo box.
Dim rngActivities As Range
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
For Each rngActivities In ws.Range("ActivitiesList")
Me.ComboBox1.AddItem rngActivities.Value
Next rngActivities

please help me. i'm new in here. please. thank you in advance.

 
0
 

Instead of writing it in initialize event, write the code in the combo change event...

and to get the value from the particular cell in an excel sheet, you have to something which refers to the particular cell like

Dim oApp As New Excel.Application
Dim oWBa As Excel.Workbook = oApp.Workbooks.Open("c:\Test.XLS")
Dim oWS As Excel.Worksheet = DirectCast(oWBa.Worksheets(1), 
Dim oRng As Excel.Range
oRng = oWS.Range("D6")
MsgBox(oRng.Value)

Hope this helps you...

Have a happy coding...:-D

 
0
 

You could query the worksheet to a datatable. Then loop thru the rows getting the items you want into the ComboBox. After that its just a matter of using the index of the ComboBox Item to get the value for your TextBox. dt.Rows(comboIndex).Item(columnNumber of value you want).ToString.

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article