【发布时间】:2021-09-23 13:47:26
【问题描述】:
我在 excel 中创建一个用户表单,其中我有一个搜索框,用于搜索 A 列中的所有值。在搜索框中选择值时。我想提取与 A 列中的值相关的所有可能值。例如.... 在要提取项目编号的组合框中。当此人选择 LR UK 1 时,我希望项目编号组合框可以选择 1 或 2....
问题是我的代码只通过了 2 的值。我可以理解为什么我的代码会通过它所做的事情,但是我正在努力让它通过项目对应列中的所有值名称范围。
Private Sub Find_Click()
Dim searchRange As Range
Dim foundCell As Range
Dim mysearch As String
mysearch = CBProjName.Value
With Sheets("Records")
Set searchRange = Sheets("Records").Range("A2", .Range("A" & .Rows.Count).End(xlUp))
End With
Set foundCell = searchRange.Find(what:=mysearch, Lookat:=xlWhole, MatchCase:=False, SearchFormat:=False)
If Not foundCell Is Nothing Then
TBCaseNumber = foundCell.Offset(0, 1).Value
CBProjNumbers.Value = foundCell.Offset(0, 2).Value 'this is the val that only displays 2
Else
MsgBox "Uh oh, things have gone a little sideways and the project " & CBProjName.Value & " cannot be located. Please try another Project!"
End If
End Sub
【问题讨论】: