|
楼主 |
发表于 2020-2-1 23:16
|
显示全部楼层
本帖最后由 OKJSJSF 于 2020-2-2 16:43 编辑
因为无法用“删除重复项方法”功能,只能用老办法“高级筛选”了,去重计算好像完全正确。 Sub cb7(control As IRibbonControl)
If MsgBox("选择当前工作表二行及以上有数据单元格后单击,可以统计出可见行的不重复行数。(注意事项:不计筛选、隐藏、真空行,但会统计空格、换行符等非打印字符)", vbOKCancel + vbInformation, "功能说明:") <> vbOK Then Exit Sub
Dim myran As Range, myran2 As Range, i As Integer, i2 As Integer, i3 As Integer
On Error GoTo errline
Set myran = Application.InputBox("请选择待统计的单元格(二行以上)", "数据设置", , , , , , 8)
If myran.Rows.Count = 1 Then Exit Sub
For Each myran2 In myran
If myran2 <> "" Then
myran.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Worksheets.Add
ActiveSheet.Paste
i = Selection.Rows.Count
i2 = Selection.Columns.Count
' Selection.RemoveDuplicates Columns:=Array(1, 2, 3, , , ,16384), Header:=xlNo 没法用变量
For i3 = i To 1 Step -1
If Application.WorksheetFunction.CountA(Rows(i3)) = 0 Then
Rows(i3).Delete
End If
Next
Rows(1).Insert
With Range("A1")
.Value = "列标"
.AutoFill Destination:=.Resize(1, i2), Type:=xlFillDefault
.CurrentRegion.AdvancedFilter Action:=xlFilterInPlace, unique:=True
Set myran = .CurrentRegion.SpecialCells(xlCellTypeVisible)
End With
With myran
For i2 = 1 To .Areas.Count
i3 = i3 + .Areas(i2).Rows.Count
Next
End With
Application.DisplayAlerts = False
ActiveSheet.Delete
Application.DisplayAlerts = True
MsgBox "选区可见行不重复行数: " & i3 - 1 & Chr(10) & "选区可见行总行数: " & i, , "计算结果:"
Set myran = Nothing
Set myran2 = Nothing
End If
Next
errline:
End Sub
|
|