Excel – 匹配项目httpstring和显示结果

我有列H包含工作表1上长的GET请求,如:

H GET /profiles/text/23493495_3492/g93id93kd GET /edit/result/393493/te3903k4d 

我想在第A列和第B列中有第二张表格,列表如下:

 AB 23493495 identifier1 3903k4 realid2 g93id realid3 

最终,我想要一个函数,将search工作表1列H列表2列A中的任何值。大多数时间没有分隔符,所以我需要它来searchGETstring内的string。 一旦表单2列A中的值与表单1列H中的值相匹配,我希望函数能够采用表单2列B中的相应文本并将其打印在表单1列I中。可能有多个匹配细胞,所以这需要考虑在内。 所以如果使用上面的例子:

在H1中,string中会有23493495和g93id的匹配。 我想要工作表1列我显示:

 I identifier1, realid3 

我最初从下面的代码开始,在那里我必须指定列表,但它不使用第二张纸或打印相应的文本。 所以我宁愿有一些符合我上面的需求,但下面是我迄今为止尝试过的一个例子:

 =ListSearchB(J2, "23493495 g93id") 

有了这个模块,我发现我修改了一下:

  Function ListSearchB(text As String, wordlist As String, Optional caseSensitive As Boolean = False) Dim strMatches As String Dim res As Variant Dim arrWords() As String arrWords = Split(wordlist) On Error Resume Next Err.Clear For Each word In arrWords If caseSensitive = False Then res = InStr(LCase(text), LCase(word)) Else res = InStr(text, word) End If If res > 0 Then strMatches = strMatches & word End If Next word If Len(strMatches) <> 0 Then strMatches = Right(strMatches, Len(strMatches)) End If ListSearchB = strMatches End Function 

这给了我:

23493495g93id在第一列,我不知道如何用逗号分隔两个。

一般来说,我宁愿使用某种方式从表2中提取列表,并按照最初指定的方式显示列I中的值。

试一试 – 只需在运行之前调整表单名称

 Sub your_sub() Dim sGet As Worksheet Dim sIDs As Worksheet Dim rget As Range Dim rIds As Range 'ADJUST SHEET NAME With Worksheets("GET") Set rget = Range(.Range("H1"), .Range("h" & .Rows.count).End(xlUp)) End With 'ADJUST SHEET NAME With Worksheets("IDs") Set rIds = Range(.Range("A1"), .Range("A" & .Rows.count).End(xlUp)) End With mys = vbNullString i = 1 For Each cget In rget For Each cIds In rIds If InStr(cget.Value, cIds) <> 0 Then mys = mys & ", " & cIds.Offset(0, 1).Value End If Next cIds If mys <> vbNullString Then mys = Right(mys, Len(mys) - 2) 'ADJUST SHEET NAME Worksheets("GET").Range("I" & i).Value = mys End If i = i + 1 mys = vbNullString Next cget End Sub