返回近似多个匹配到一个combobox

我想从列中返回多个匹配到一个combobox。 所以,如果我有一个这样的名为“variables:”,并search“variables1”

在这里输入图像说明

然后我想在ComboBox中输出这样的内容。 如果没有find匹配,那么“不匹配”。 在这里输入图像说明

我将使用“近似匹配”这一假设:a)不区分大小写,b)仅仅要求searchstring在Range值内。 在UserForm尝试下面的代码:

 Option Explicit Private Sub CommandButton1_Click() Dim rngSource As Range Dim rngCell As Range Dim strValueToApproximatelyMatch As String Dim lngCounter As Long Dim lngResultCount As Long 'get candidate values and put to an array Set rngSource = Sheet1.Range("A2:A10") 'get value to match approximately strValueToApproximatelyMatch = Me.TextBox1.Value 'clear combo box Me.ComboBox1.Clear 'set result count to 0 lngResultCount = 0 'iterate array and look for approximate match to input For lngCounter = 1 To rngSource.Rows.Count 'get candidate Set rngCell = rngSource.Cells(lngCounter, 1) 'test candidate against value to approximately match If InStr(1, rngCell.Value, strValueToApproximatelyMatch, vbTextCompare) > 0 Then 'add to list if test passed Me.ComboBox1.AddItem rngCell.Value 'increment result count lngResultCount = lngResultCount + 1 End If Next lngCounter 'add the no match if result count =0 If lngResultCount = 0 Then Me.ComboBox1.AddItem "No Match" End If End Sub 

这是我得到的输出:

在这里输入图像说明