做了一自定义函数,用于找一个表中的数据是否被指定的字符串包含,表中的数据在同一个文件时,框住这个表就能用,要是在另一个表里,框住结果就不对,请问是为什么?
Public Function blookup(a1 As Range, r1 As Range, b1 As Integer) '(a1为单个单元格,r1为表,b1为想返回的表中对应单元格同行第b1例的值)
If (a1.Value <> "") Then
For Each c In r1
If (0 <> InStr(1, a1.Value, c.Value, 1)) Then '字符串a1是否包含c
blookup = Cells(c.Row(), c.Column() + b1 - 1).Value
Exit For
End If
Next c
Else
blookup = ""
End If End Function
Public Function blookup(a1 As Range, r1 As Range, b1 As Integer) '(a1为单个单元格,r1为表,b1为想返回的表中对应单元格同行第b1例的值)
If (a1.Value <> "") Then
For Each c In r1
If (0 <> InStr(1, a1.Value, c.Value, 1)) Then '字符串a1是否包含c
blookup = Cells(c.Row(), c.Column() + b1 - 1).Value
Exit For
End If
Next c
Else
blookup = ""
End If End Function
r1为表=====〉应该是指定的单元格区域吧?
将blookup = Cells(c.Row(), c.Column() + b1 - 1).Value 该成
blookup = c.Offset(0, b1 - 1).Value 试试
5 照明 0.9
6 通讯 0.7
7 通信 0.7
8 电梯 0.55
9 客梯 0.55
10 无功 1
11 进线 0.92
12 计量 0.92
13 母联 0.8
14 备用 0.8
15 0.8
????????应该是这样:=blookup(sheet2.range("e23"),sheet1.range("f5:f15"),2)