|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
第二种- Sub kong2()
- aa = "表2"
- If Objectsexists(ActiveSheet.ListObjects, (aa)) Then
- If IsListobjectFiltered(ActiveSheet.ListObjects(aa)) Then
- Set bb = ActiveSheet.ListObjects(aa).AutoFilter.Filters
- ReDim ar(1 To bb.Count, 1 To 2)
- cc = 0
- For i = 1 To bb.Count
- If bb.Item(i).On Then
- cc = cc + 1: ar(cc, 1) = i:
- ar(cc, 2) = bb.Item(i).Count
- If ans < ar(cc, 2) Then ans = ar(cc, 2)
- End If
- Next
- If cc > 0 Then
- ReDim arr(1 To ans + 1, 1 To cc): dd = 0
- drr = ActiveSheet.ListObjects(aa).AutoFilter.Range.Value2
- For i = 1 To cc
- arr(1, i) = drr(1, ar(i, 1))
- Next
- For i = 1 To cc
- If ar(i, 2) > 1 Then
- ss = Split(Replace(Join(bb.Item(ar(i, 1)).Criteria1, ","), "=", ""), ",")
- For j = 0 To UBound(ss)
- arr(j + 2, i) = IIf(IsNumeric(ss(j)), Val(ss(j)), ss(j))
- Next
- Else
- arr(2, i) = Replace(bb.Item(ar(i, 1)).Criteria1, "=", "")
- arr(2, i) = IIf(IsNumeric(arr(2, i)), Val(arr(2, i)), arr(2, i))
- End If
- Next
- Range("a" & ActiveSheet.UsedRange.Rows.Count).Resize(UBound(arr), cc) = arr
- End If
- Else
- MsgBox aa & " ListObjects 没有被筛选"
- End If
- Else
- MsgBox "没有 " & aa & " 这个 ListObjects"
- End If
- End Sub
- Function Objectsexists(bb As Object, aa As String) As Boolean '''ListObjects表判断
- On Error GoTo err
- If Len(bb(aa)) Then Objectsexists = True
- err:
- End Function
- Function IsListobjectFiltered(ByVal listObj As ListObject) As Boolean '''ListObjects筛选判断
- If listObj.ShowAutoFilter Then
- If listObj.AutoFilter.FilterMode Then
- IsListobjectFiltered = True
- Exit Function
- End If
- End If
- IsListobjectFiltered = False
- End Function
复制代码 |
评分
-
1
查看全部评分
-
|