ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

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

[求助] 请高手帮忙,用VBA编程

[复制链接]

TA的精华主题

TA的得分主题

发表于 2019-1-21 22:21 | 显示全部楼层 |阅读模式
本帖最后由 ytnet 于 2019-1-23 20:19 编辑

求助大神们用VBA编程,辛苦大神们!

TA的精华主题

TA的得分主题

发表于 2019-1-22 16:01 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
  1. ption Explicit

  2. Const Status$ = "身份"
  3. Const Title$ = "职称"
  4. Const PHD$ = "博"
  5. Const MA$ = "硕"
  6. Const BA$ = "本"
  7. Const Coll$ = "专"

  8. Const PaysCales$ = "薪级"

  9. Sub Main()
  10.     Dim Ar, I&, Dic, Keys, Items, J&
  11.     Ar = Sheets("员工统计表").UsedRange
  12.     Set Dic = ParseData
  13.     For I = 2 To UBound(Ar)
  14.     If Ar(I, 11) = "干部" Then
  15.            If IsEmpty(Dic(Ar(I, 11))(Ar(I, 16))(Ar(I, 12))) Then
  16.            
  17.            Else
  18.                Keys = Dic(Ar(I, 11))(Ar(I, 16))(Ar(I, 12)).Keys
  19.                Items = Dic(Ar(I, 11))(Ar(I, 16))(Ar(I, 12)).Items
  20.            End If
  21.         
  22.            For J = 0 To UBound(Keys)
  23.                If Ar(I, 14) >= Keys(J) Then
  24.                    Cells(I, "t") = Items(J)
  25.                    Exit For
  26.                End If
  27.            Next J
  28.     End If
  29.     Next I
  30. On Error GoTo 0
  31. End Sub


  32. Public Function ParseData()
  33.     Dim Dcol, Dic, Dtemp
  34.     Dim Ar, I&
  35.     Ar = Sheets(PaysCales).Range("a1").CurrentRegion
  36. '=====================列字段===========================
  37.     Set Dcol = CreateObject("Scripting.Dictionary")
  38.     For I = 1 To UBound(Ar, 2)
  39.         Dcol(Ar(1, I)) = I
  40.     Next I
  41. '=======================================================
  42.     Set Dic = CreateObject("Scripting.Dictionary")
  43.     For I = 2 To UBound(Ar)
  44.         '依据(身份)创建字典
  45.         If IsEmpty(Dic(Ar(I, Dcol(Status)))) Then
  46.             Set Dic(Ar(I, Dcol(Status))) = CreateObject("Scripting.Dictionary")
  47.         End If
  48.         Set Dtemp = Dic(Ar(I, Dcol(Status)))
  49.         
  50.         '依据(身份)(职称)创建字典
  51.         If IsEmpty(Dtemp(Ar(I, Dcol(Title)))) Then
  52.             Set Dtemp(Ar(I, Dcol(Title))) = CreateObject("Scripting.Dictionary")
  53.         End If
  54.         Set Dtemp = Dtemp(Ar(I, Dcol(Title)))
  55.         '依据(身份)(职称)(P|M|B|C)创建字典
  56.       
  57.         If IsEmpty(Dtemp(PHD)) Then Set Dtemp(PHD) = CreateObject("Scripting.Dictionary")
  58.         If IsEmpty(Dtemp(MA)) Then Set Dtemp(MA) = CreateObject("Scripting.Dictionary")
  59.         If IsEmpty(Dtemp(BA)) Then Set Dtemp(BA) = CreateObject("Scripting.Dictionary")
  60.         If IsEmpty(Dtemp(Coll)) Then Set Dtemp(Coll) = CreateObject("Scripting.Dictionary")
  61.         
  62.         Dtemp(PHD)(Ar(I, Dcol(PHD))) = Ar(I, 1)
  63.         Dtemp(MA)(Ar(I, Dcol(MA))) = Ar(I, 1)
  64.         Dtemp(BA)(Ar(I, Dcol(BA))) = Ar(I, 1)
  65.         Dtemp(Coll)(Ar(I, Dcol(Coll))) = Ar(I, 1)
  66.       
  67.     Next I

  68.     Set ParseData = Dic
  69.     Set Dic = Nothing
  70.     Set Dtemp = Nothing
  71.     Set Dcol = Nothing
  72. End Function
复制代码

TA的精华主题

TA的得分主题

发表于 2019-1-22 16:03 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
抛转引玉,做了干部部分的薪级识别。思维有些乱了

新建 WinRAR ZIP 压缩文件.zip

22.85 KB, 下载次数: 9

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

本版积分规则

关闭

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

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

GMT+8, 2024-4-26 21:07 , Processed in 0.033113 second(s), 11 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

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

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

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