'自定义公式-按ALT+11-插入-模块(去重合并)
Function 去重合并(a As Range)
For i = 1 To a.Rows.Count
If InStr(t, a.Cells(i, 1)) = 0 Then t = t & "," & a.Cells(i, 1)
If a.Cells(i, 1) = "" Then Exit For
Next
arr = Split(Right(t, Len(t) - 1), ",", -1, 1)
For j = 0 To UBound(arr)
去重合并 = 去重合并 & arr(j)
Next
End Function
'自定义公式-按ALT+11-插入-模块(去重合并)
Function 去重合并(a As Range)
For i = 1 To a.Rows.Count
If InStr(t, a.Cells(i, 1)) = 0 And i Mod 2 = 1 Then t = t & "," & a.Cells(i, 1)
If a.Cells(i, 1) = "" Then Exit For
Next
arr = Split(Right(t, Len(t) - 1), ",", -1, 1)
For j = 0 To UBound(arr)
去重合并 = 去重合并 & arr(j)
Next
End Function
这个只会合并1/3/5/7....等单数的单元格并去重
'自定义公式-按ALT+11-插入-模块(去重合并)
Function 去重合并(a As Range)
For i = 1 To a.Rows.Count
If InStr(t, a.Cells(i, 1)) = 0 And a.Cells(i, 1).MergeCells Then t = t & "," & a.Cells(i, 1)
Next
去重合并 = Right(t, Len(t) - 1)
End Function
谢谢大神不厌其烦的回答,成功解决了。果然VBA无所不能。特别想学习一下,有没有什么书可以推荐给我。向大神学习!
追答我是自学的,但是我有c++基础,我没看过书,不懂就百度搜索