Guest User

Untitled

a guest
Sep 22nd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. Sub Sample1()
  2.  
  3. keyWord = "テスト" '検索ワード
  4. Set Rng = Range("A1:E10") '検索範囲
  5.  
  6. '部分一致:xlPart
  7. '完全一致:xlWhole
  8. Set obj = Rng.Find(keyWord, LookAt:=xlPart)
  9.  
  10. '検索結果判定
  11. If obj Is Nothing Then
  12. MsgBox keyWord & "は見つかりません"
  13. Else
  14. '1つ目の位置を記憶
  15. t_Row = obj.Row
  16. t_Column = obj.Column
  17. Count = 1
  18. Do
  19. Cells(Count, 6) = obj.Row 'Y
  20. Cells(Count, 7) = obj.Column 'X
  21. Cells(Count, 8) = obj.Value 'セルの内容
  22. Count = Count + 1
  23.  
  24. '次の検索結果へ
  25. Set obj = Rng.FindNext(obj)
  26. '同じ箇所に戻るまでループ
  27. Loop While t_Row <> obj.Row And t_Column <> obj.Column
  28. End If
  29.  
  30. End Sub
Add Comment
Please, Sign In to add comment