首页 > 编程语言 > 详细

VBA Find命令应用实例

时间:2020-12-10 17:37:28      阅读:32      评论:0      收藏:0      [点我收藏+]
Function 返回班组所在部门(bz_name As Variant) Dim rang As Range Set rang = ThisWorkbook.Worksheets("员工指标库").Range("B1:B2000").Find(bz_name) 返回班组所在部门 = rang(1, 0) End Function
Function 返回班组编码(bz_name As Variant)
   Dim rang As Range
   Set rang = ThisWorkbook.Worksheets("组织架构").Range("I1:I100").Find(bz_name)
   返回班组编码 = rang(1, 0)
End Function
Function 返回班组指标块(sig As Variant, bz_name As Variant)
  Dim rang As Range
  If sig = 0 Then    // 0:块首;1:块尾
    Set rang = ThisWorkbook.Worksheets("员工指标库").Range("B1:B2000").Find(bz_name)
    Else
    Set rang = ThisWorkbook.Worksheets("员工指标库").Range("B1:B2000").Find(bz_name, , xlValues, , , xlPrevious)
  End If
  If rang Is Nothing Then
  返回人员指标块 = 0
  Else
  返回班组指标块 = rang.Row
  End If
End Function
Function 返回人员指标块(sig As Variant, bz_name As Variant)
  Dim rang As Range
  If sig = 0 Then    // 0:块首;1:块尾
    Set rang = ThisWorkbook.Worksheets("员工指标库").Range("E1:e2000").Find(bz_name)
    Else
    Set rang = ThisWorkbook.Worksheets("员工指标库").Range("E1:e2000").Find(bz_name, , xlValues, , , xlPrevious)
  End If
  If rang Is Nothing Then
  返回人员指标块 = 0
  Else
  返回人员指标块 = rang.Row
  End If
End Function
Function 返回人员编码指标块(sig As Variant, ry_code As Variant)
  Dim rang As Range
  If sig = 0 Then   // 0:块首;1:块尾
    Set rang = ThisWorkbook.Worksheets("员工指标库").Range("D1:d2000").Find(ry_code)
    Else
    Set rang = ThisWorkbook.Worksheets("员工指标库").Range("D1:d2000").Find(ry_code, , xlValues, , , xlPrevious)
  End If
  返回人员指标块 = rang.Row
End Function
Function 返回班组名称存在否(bz_name As Variant)
   Call 锁定页面(0, "组织架构")
   Dim rang As Range
   返回班组名称存在否 = 1
   Set rang = ThisWorkbook.Worksheets("组织架构").Range("D1:D100").Find(bz_name)
   If rang Is Nothing Then
      返回班组名称存在否 = 0
   End If

End Function
Function 返回部门名称存在否(bm_name As Variant)
   Call 锁定页面(0, "组织架构")
   Dim rang As Range
   返回部门名称存在否 = 0
   Set rang = ThisWorkbook.Worksheets("组织架构").Range("G1:G100").Find(bm_name)
   If rang <> "" Then
   返回部门名称存在否 = 1
   End If

End Function

VBA Find命令应用实例

原文:https://blog.51cto.com/12815848/2562430

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!