1,105,399 Community Members

combo box and textbox

jennafher
Newbie Poster
1 post since Sep 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
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.

Member Avatar
ss125
Posting Whiz in Training
200 posts since Jul 2013
Reputation Points: 18 [?]
Q&As Helped to Solve: 22 [?]
Skill Endorsements: 0 [?]
 
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

Member Avatar
kRod
Junior Poster
139 posts since May 2012
Reputation Points: 49 [?]
Q&As Helped to Solve: 35 [?]
Skill Endorsements: 6 [?]
 
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 three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article