Advertisement
ferdinand

[Tutorial] Find Excel (Macro)

Feb 25th, 2012
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. Search a value in column &copy row...[Excel VBA]
  2. http://pastebin.com/di3tdZEJ
  3. [Q&A] search macro in excel using VB
  4. http://pastebin.com/KrnQLT5Y
  5. ---------------------------------------------------------------
  6. [Tutorial] Find Excel (Macro)
  7. Syntax :
  8. Cells.Find(What:="Cat", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
  9.  
  10. xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
  11.  
  12. , SearchFormat:=False).Activate
  13.  
  14. '--Sample 1:
  15. '--Sub FindCatOtherSheet()
  16. Dim rFound As Range
  17.  
  18. On Error Resume Next
  19.  
  20. With Sheet1
  21. Set rFound = .Columns(1).Find(What:="Cat", After:=.Cells(1, 1), LookIn:=xlValues, LookAt:= _
  22. xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
  23. , SearchFormat:=False)
  24.  
  25. On Error GoTo 0
  26.  
  27. If Not rFound Is Nothing Then Application.Goto rFound, True
  28. End With
  29.  
  30. End Sub
  31.  
  32. '--Sample 2:
  33. '--Sub Find_Bold_Cat()
  34. Dim lCount As Long
  35. Dim rFoundCell As Range
  36.  
  37. Set rFoundCell = Range("A1")
  38. For lCount = 1 To WorksheetFunction.CountIf(Columns(1), "Cat")
  39. Set rFoundCell = Columns(1).Find(What:="Cat", After:=rFoundCell, _
  40. LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
  41. SearchDirection:=xlNext, MatchCase:=False)
  42. With rFoundCell
  43. .ClearComments
  44. .AddComment Text:="Cat lives here"
  45. End With
  46. Next lCount
  47.  
  48. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement