返回列表 上一主題 發帖

[發問] 請問透過VBA雙向查詢,如何區別英文大小寫?,也就是字要完全一樣

回復 7# peter460191
  1. Private Sub Worksheet_Change(ByVal Target As Range)
  2. Static Mystr$
  3. Dim A As Range
  4. If Intersect(Target, [C5:C6]) Is Nothing Then Exit Sub '[C5:C6]為資料輸入位置,可任意改變
  5. Application.EnableEvents = False
  6. Set A = Columns("A:B").Find(Target, lookat:=xlWhole, MatchCase:=True) 'A:B為資料來源位置欄位,可任意改變
  7. If InStr(1, Mystr, Target, vbBinaryCompare) > 0 Then MsgBox "區分大小寫,已查詢過": GoTo 10 '區分大小寫
  8. 'If InStr(Mystr, Target) > 0 Then MsgBox "不分大小寫,已查詢過": GoTo 10 '不分大小寫
  9. If A Is Nothing Then MsgBox "輸入錯誤": [C5:C6] = "": GoTo 10 '[C5:C6]為資料輸入位置,可任意改變
  10. [C5] = Cells(A.Row, 1).Value '[C5:C6]為資料輸入位置,可任意改變
  11. [C6] = Cells(A.Row, 2) '[C5:C6]為資料輸入位置,可任意改變
  12. If Target.Address = "$C$5" Then Mystr = Mystr & "," & Target
  13. 10
  14. Application.EnableEvents = True
  15. End Sub
複製代碼
學海無涯_不恥下問

TOP

        靜思自在 : 原諒別人就是善待自己。
返回列表 上一主題