对VBA非常陌生,所以请原谅我的无知。
您将如何更改下面的代码以将结果返回到行而不是字符串中?
提前致谢....
数据
Acct No CropType
------- ---------
0001 Grain
0001 OilSeed
0001 Hay
0002 Grain
功能
=vlookupall("0001", A:A, 1, " ")
这是代码:
Function VLookupAll(ByVal lookup_value As String, _
ByVal lookup_column As range, _
ByVal return_value_column As Long, _
Optional seperator As String = ", ") As String
Application.ScreenUpdating = False
Dim i As Long
Dim result As String
For i = 1 To lookup_column.Rows.count
If Len(lookup_column(i, 1).text) <> 0 Then
If lookup_column(i, 1).text = lookup_value Then
result = result & (lookup_column(i).offset(0, return_value_column).text & seperator)
End If
End If
Next
If Len(result) <> 0 Then
result = Left(result, Len(result) - Len(seperator))
End If
VLookupAll = result
Application.ScreenUpdating = True
End FunctionNotes: