ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 140|回复: 6

[求助] 怎么用VBA自动筛查excel数据表

[复制链接]

TA的精华主题

TA的得分主题

发表于 2024-6-4 13:47 | 显示全部楼层 |阅读模式
本帖最后由 xiangye30520 于 2024-6-4 13:50 编辑

如附件 表(sheet1 )品目列   想把表(需求品目)A列的数据自动筛查出来并另存为一张表格,感谢。

test2.rar

24.43 KB, 下载次数: 6

TA的精华主题

TA的得分主题

发表于 2024-6-4 14:10 | 显示全部楼层
image.png

test2.rar

32.32 KB, 下载次数: 1

TA的精华主题

TA的得分主题

发表于 2024-6-4 14:30 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
Sub 筛选()
Application.ScreenUpdating = False
Dim ar As Variant, cr As Variant
Dim i As Long, r As Long
Dim br()
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("需求品目")
    r = .Cells(Rows.Count, 1).End(xlUp).Row
    ar = .Range("a1:a" & r)
End With
For i = 1 To UBound(ar)
    If ar(i, 1) <> "" Then
        d(ar(i, 1)) = ""
    End If
Next i
With Sheets("Sheet1")
    cr = .[a1].CurrentRegion
End With
ReDim br(1 To UBound(cr), 1 To UBound(cr, 2))
For i = 2 To UBound(cr)
    If cr(i, 3) <> "" Then
        If d.exists(cr(i, 3)) Then
            n = n + 1
            For j = 1 To UBound(cr, 2)
                br(n, j) = cr(i, j)
            Next j
        End If
    End If
Next i
If n = "" Then MsgBox "没有符合条件的数据!": End
With Sheets("筛选结果")
    .[a1].CurrentRegion = Empty
    .[a1].Resize(1, UBound(cr, 2)) = cr
    .[a2].Resize(n, UBound(br, 2)) = br
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub

TA的精华主题

TA的得分主题

发表于 2024-6-4 14:32 | 显示全部楼层
test2.rar (44.09 KB, 下载次数: 4)

TA的精华主题

TA的得分主题

发表于 2024-6-4 14:45 | 显示全部楼层
union

image.jpg

test2.rar

33 KB, 下载次数: 1

TA的精华主题

TA的得分主题

发表于 2024-6-4 14:45 | 显示全部楼层
参与一下。。。

test3.zip

41.66 KB, 下载次数: 3

TA的精华主题

TA的得分主题

发表于 2024-6-4 14:46 | 显示全部楼层
参与一下。。。

  1. Sub ykcbf()   '//2024.6.4
  2.     Application.ScreenUpdating = False
  3.     Set d = CreateObject("Scripting.Dictionary")
  4.     With Sheets("需求品目")
  5.         r = .Cells(Rows.Count, 1).End(3).Row
  6.         arr = .[a1].Resize(r, 1)
  7.     End With
  8.     For i = 1 To UBound(arr)
  9.         s = Trim(arr(i, 1))
  10.         d(s) = ""
  11.     Next
  12.     With Sheets("Sheet1")
  13.         r = .Cells(Rows.Count, 1).End(3).Row
  14.         c = .UsedRange.Columns.Count
  15.         arr = .[a1].Resize(r, c)
  16.         ReDim brr(1 To UBound(arr), 1 To UBound(arr, 2))
  17.         For i = 2 To UBound(arr)
  18.             s = arr(i, 3)
  19.             If d.exists(s) Then
  20.                 m = m + 1
  21.                 For j = 1 To UBound(arr, 2)
  22.                     brr(m, j) = arr(i, j)
  23.                 Next
  24.             End If
  25.         Next
  26.     End With
  27.     With Sheets("结果表")
  28.         .UsedRange.Offset(1).Clear
  29.         .[a1].Resize(1, c).Interior.Color = 49407
  30.         With .[a2].Resize(m, c)
  31.             .Value = brr
  32.             .Borders.LineStyle = 1
  33.             .HorizontalAlignment = xlCenter  '//列居中
  34.             .VerticalAlignment = xlCenter
  35.         End With
  36.     End With
  37.     Set d = Nothing
  38.     Application.ScreenUpdating = True
  39.     MsgBox "OK!"
  40. End Sub
复制代码


您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

关闭

最新热点上一条 /1 下一条

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-6-18 21:58 , Processed in 0.046572 second(s), 11 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表