其他分享
首页 > 其他分享> > VBA Find命令应用实例

VBA Find命令应用实例

作者:互联网

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

标签:Function,VBA,End,name,rang,Range,实例,Find,bz
来源: https://blog.51cto.com/12815848/2562430