本帖最后由 jonsonchang 于 2024-5-30 16:43 编辑
附件已做好例子和宏
通过界面点击删除重复项,录制到下方宏命令,Array有多列,因为每次操作的列数不确定,需要改为变量,但是Array放入变量后报错,请大神看下是否有办法解决?谢谢
Sub 宏2()
T = ActiveSheet.UsedRange.Columns.Count
For i = 1 To T
columnArray = columnArray & "," & i
Next i
AA = Mid(columnArray, 2)
'根据录制宏调整的Array变量,Array(AA)报错
ActiveSheet.Range("$A$1:$BM$222").RemoveDuplicates Columns:=Array(AA), Header:=xlYes
'录制宏
' ActiveSheet.Range("$A$1:$BM$222").RemoveDuplicates Columns:=Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65), Header:=xlYes
Stop
End Sub
|