|
做了两个自定义函数来提取姓名,顺便把你花名册里的几个公式优化了一下,留意红色字体所在列。
- Option Explicit
- Function GetZhicheng(strZhicheng$, strDengji$)
- On Error Resume Next
- Application.Volatile False
- Dim cn As Object, sql$, arr, i%, strTemp$
- Set cn = CreateObject("ADODB.Connection")
- sql = "select 姓名 from [HR$B3:BO65536] where like '" & Replace(strZhicheng, " ", "") & "%' and 等级='" & Replace(strDengji, " ", "") & "'"
- cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='Excel 12.0;HDR=yes;IMEX=2';Data Source=" & ThisWorkbook.FullName
- arr = cn.Execute(sql).GetRows
- cn.Close
- Set cn = Nothing
- For i = 0 To UBound(arr, 2)
- strTemp = strTemp & "," & arr(0, i)
- Next
- GetZhicheng = Right(strTemp, Len(strTemp) - 1)
- End Function
- Function GetZhuce(strZhuce$)
- On Error Resume Next
- Application.Volatile False
- Dim cn As Object, sql$, arr, i%, strTemp$
- Set cn = CreateObject("ADODB.Connection")
- sql = "select 姓名 from [HR$B3:BO65536] where 职业资格='" & Replace(strZhuce, " ", "") & "'"
- cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='Excel 12.0;HDR=yes;IMEX=2';Data Source=" & ThisWorkbook.FullName
- arr = cn.Execute(sql).GetRows
- cn.Close
- Set cn = Nothing
- For i = 0 To UBound(arr, 2)
- strTemp = strTemp & "," & arr(0, i)
- Next
- GetZhuce = Right(strTemp, Len(strTemp) - 1)
- End Function
复制代码 |
-
-
HR信息.rar
195.22 KB, 下载次数: 95
含VBA代码,打开请启用宏
|