单元格字符串交集
- 功能:计算两个开头字符串相同的内容
- 注意:Excel要启用宏,且文件要保存为.xlsm格式
- 示例:
a). StringIntersect(“abc”,“abcd”) 结果为:abc
b). StringIntersect(“123”,“1”) 结果为:1
Function StringIntersect(s1 As String, s2 As String) As String
Dim strlen As Integer
Dim temLen As Integer
Dim chekV As Boolean
Dim temStr As String
chekV = True
strlen = Len(s2)
temLen = 0
Do
temLen = temLen + 1
temStr = Left(s2, temLen)
If (InStr(s1, temStr) < 1) Then chekV = False
Loop Until chekV = False Or temLen > strlen
StringIntersect = Left(s2, temLen - 1)
End Function