VBA找单元格对应重复的数字
发布网友
发布时间:2023-08-19 05:50
我来回答
共1个回答
热心网友
时间:2023-09-07 20:17
Function ProjectALL(r, c) 'r是行号,c是列号
m1 = Cells(r - 1, c).Value '上一行数据
m2 = Cells(r, c).Value '本行数据
l1 = Len(m1) 'm1长度
l2 = Len(m2) ‘m2长度
If l1 < l2 Then ’l1<l2,就只需要比较l1这么长的数据,反之则比较l2这么长的数据
For i = 1 To l1
t1 = Mid(m1, i, 1)
t2 = Mid(m2, i, 1)
If t1 = t2 Then
k = k & t1 & "," ‘相同位置相同字符,则记录,分隔符为逗号。
End If
Next
Else
For i = 1 To l2
t1 = Mid(m1, i, 1)
t2 = Mid(m2, i, 1)
If t1 = t2 Then
k = k & t1 & ","
End If
Next
End If
ProjectALL = Left(k, Len(k) - 1) ’去掉最后一个逗号
End Function