vba函数foreach范围错误#value

我不是一个VBA开发者,但我需要一个VLOOKUP函数multile值返回。

我发现这一个:

Public Function CercaTableMultiplo(lookupval, lookuprange As Range, indexcol As Long) 'updateby Extendoffice 20151118 Dim x As Range Dim result As String result = "" For Each x In lookuprange If x = lookupval Then result = result & " " & x.Offset(0, indexcol - 1) End If Next x CercaTableMultiplo = result End Function 

我编辑它作为休耕

 Public Function CercaTableMultiplo(lookupval, lookuprange As Range, indexcol As Long, delimitator) Dim x As Range Dim result As String result = "" Dim first As Boolean first = True For Each x In lookuprange If x = lookupval Then If first = True Then result = result & x.Offset(0, indexcol - 1) first = False Else result = result & delimitator & x.Offset(0, indexcol - 1) End If End If Next x CercaTableMultiplo = result End Function 

参数是(F217; Foglio2!E:G; 3;“,”)

它的工作原理是:

  • 第一列很less, 第二列是空的第三列是填充的。

不工作时:

  • 第一列很less, 第二列是填充 (如描述文本), 第三列是填充。

我想这是一个溢出问题,但我的短VBA开发人员的经验停在这里,有一些检查,我可以做什么?