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
相關文章
相關標籤/搜索