【发布时间】:2015-04-25 20:02:42
【问题描述】:
我正在 Excel 中编写 VBA 代码,以根据在 ComboBox 中选择的值将多行放入 TextBox。这是我编写的以下代码。它只列出了最后一行,但没有列出我想要的所有行。前任。第 76 列是 ComboBox 将显示值的位置。如果值匹配,那么它应该在 TextBox 中返回我在第 77 列中找到的所有值。即,如果我在我的 ComboBox BFSI 中选择,它应该返回我印度和 SBI 的 LIC。但我的代码只返回 SBI。
Private Sub ComboBox22_Change()
'Variable Declaration
Dim iRow, StartLine, EndLine As Integer
EndLine = 50
iRow = 6
'Clear Combobox2 before loading items
TextBox21.Text = ""
For StartLine = 1 To EndLine
If ComboBox22.Text = Sheets("Pivots").Cells(iRow, 76) Then
TextBox21.Text = Sheets("Pivots").Cells(iRow, 77)
End If
iRow = iRow + 1
Next StartLine
End Sub
【问题讨论】: