Reading Excel cell into Combo box or array in VB?
Posted on 2006-04-06
I have a VB application in which I'm able to read Excel cell range into a combo box. The issue is that in cell A1 I have the category, and B1 is the description. What I want to be able to do is if a user selects an item from the combo box, the appropriate description displays. The only way I can think of is using an array to read from the Excel file and then populate the combo box from the array. Within the combo box, depending on what is selected will pull the description from the combo box into the text box next to it. The problem is I'm not sure how I would go about coding this. Anyone can provide an example? I got a sample below which reads from an Excel file into a combo, so not sure if I can just tweak this code to do what I wanted.
Private Sub Form_Load()
Dim xl As New Excel.Application
Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet
Dim iRow As Integer
Set wb = xl.Workbooks.Open("C:\Spec.xls")
Set ws = wb.Sheets("sheet1")
For iRow = 11 To 13
cboModes1.AddItem ws.Cells(iRow, 1)
cboModes1.ItemData(cboModes1.ListCount - 1) = ws.Cells(iRow, 13)
Set xl = Nothing
Set wb = Nothing
Set ws = Nothing