如何编写VBA代码实现多条件的筛选

悬崖跳舞被人砍 2014-10-29 11:23:38
我有一表,如下
所有号码 匹配号码 标注
11347851412 11345781124 成功
11347851413 11347851412 失败
11347851414 11314571154 成功
11311571154 11452364782 失败
11311571155 成功
11311571156
11311571157

要筛选出【匹配号码】列中与【所有号码】一致的号码且在【标注】中为“成功”的记录条数。
虽然这个直接在表格中用vlookup函数可以做出来,但是还是想看一下VBA语句应该怎么写,求教~
...全文
1497 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaodeerdeer 2014-11-04
  • 打赏
  • 举报
回复
不错 还是需要自己慢慢研究的 哈哈
  • 打赏
  • 举报
回复
引用 1 楼 xiaodeerdeer 的回复:
用循环 for index_all = 0 to all_max for index_find = 0 to find_max if cells(index_all,"A") = cells(index_find,"B") and cells(index_find,"C") = "成功"then '处理 end if next index 如果不想用cells的话 可以把range()跟一个数组想连用 去循环数组
已经做出来了哩,

Sub test()
  Dim d As Object
  Dim e As Object
  Dim r As Long, i As Long
  Dim arr, brr(), crr()
  Set d = CreateObject("scripting.dictionary")
  Set e = CreateObject("scripting.dictionary")
  With Worksheets("sheet1")
    r = .Cells(.Rows.Count, 1).End(xlUp).Row
    arr = .Range("a2:c" & r)
    ReDim brr(1 To UBound(arr), 1 To 1)
    ReDim crr(1 To UBound(arr), 1 To 1)
    For i = 1 To UBound(arr)
      d(arr(i, 1)) = ""
      e(arr(i, 1)) = ""
    Next
    m = 0
    n = 0
    For i = 1 To UBound(arr)
      If d.Exists(arr(i, 2)) And arr(i, 3) = "成功" Then
        m = m + 1
        brr(m, 1) = arr(i, 2)
      End If
      If e.Exists(arr(i, 2)) And (arr(i, 3) Like "失*") Then
        n = n + 1
        crr(n, 1) = arr(i, 2)
      End If
    Next
    .Range("d2").Resize(UBound(brr), 1) = brr
    .Range("e2").Resize(UBound(crr), 1) = crr
  End With
End Sub
这是能够同时统计出失败与成功的语句~
xiaodeerdeer 2014-10-29
  • 打赏
  • 举报
回复
用循环 for index_all = 0 to all_max for index_find = 0 to find_max if cells(index_all,"A") = cells(index_find,"B") and cells(index_find,"C") = "成功"then '处理 end if next index 如果不想用cells的话 可以把range()跟一个数组想连用 去循环数组

2,503

社区成员

发帖
与我相关
我的任务
社区描述
VBA(Visual Basic for Applications)是Visual Basic的一种宏语言,是在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言。
社区管理员
  • VBA
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧