我在Sheet1中有一个包含3列的价目表:
医疗程序
键入
程序价值
在userform中,我需要在Textbox1中根据在combobox1中选择的条件(具有可在Sheet1中的Medical Procedure列中找到的值)和label1中的标题返回过程的值(如果填充了alrealdy)可以在Sheet1中的Type列中遇到的值。
我在用户B Hart的stackoverflow中尝试了这个(感谢B Hart!),但是我无法将其更改为在文本框中作为数值返回(此vba将找到的值插入到而是列表框)。另一个问题是下面的标准是两个组合框。我需要将两个标准放在一个组合框中,另一个放在标签中。
Private Sub GetCondStrandValue()
Dim iRow As Long
Dim strValue As String
strValue = vbNullString
If Me.ComboBox1.Value = vbNullString Or Me.ComboBox2.Value = vbNullString Then Exit Sub
With Planilha1
For iRow = 2 To .Range("A65536").End(xlUp).Row
If StrComp(.Cells(iRow, 1).Value, Me.ComboBox1.Value, 1) = 0 And _
StrComp(.Cells(iRow, 2).Value, Me.ComboBox2.Value, 1) = 0 Then
strValue = .Cells(iRow, 3).Value
Exit For
End If
Next
End With
If strValue = vbNullString Then Exit Sub
With Me.ListBox1
'If you only want a single value in the listbox un-comment the .clear line
'Otherwise, values will continue to be added
'.Clear
.AddItem strValue
.Value = strValue
.SetFocus
End With
End Sub
答案 0 :(得分:0)
也许是这样的:
Private Sub combobox1_Change()
Dim lastRow As Integer
lastRow = Cells(Rows.Count, 1).End(xlUp).Row
With Me
For r = 2 To lastRow
If Sheets("Sheet1").Cells(r, 1) = .ComboBox1.Value And Sheets("Sheet1").Cells(r, 2) = .Label1.Caption Then
.TextBox1.Text = Sheets("Sheet1").Cells(r, 3)
Exit For
End If
Next
End With
End Sub