Guest User

Untitled

a guest
Oct 20th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. Sub FindAndBold()
  2. Dim sFind As String
  3. Dim rCell As Range
  4. Dim rng As Range
  5. Dim lCount As Long
  6. Dim iLen As Integer
  7. Dim iFind As Integer
  8. Dim iStart As Integer
  9.  
  10. On Error Resume Next
  11. Set rng = ActiveSheet.UsedRange. _
  12. SpecialCells(xlCellTypeConstants, xlTextValues)
  13. On Error GoTo ErrHandler
  14. If rng Is Nothing Then
  15. MsgBox "There are no cells with text"
  16. GoTo ExitHandler
  17. End If
  18.  
  19. sFind = InputBox( _
  20. Prompt:="Skriv in dina initialer", _
  21. Title:="Dina initialer")
  22. If sFind = "" Then
  23. MsgBox "Du skrev inget"
  24. GoTo ExitHandler
  25. End If
  26.  
  27. iLen = Len(sFind)
  28. lCount = 0
  29.  
  30. For Each rCell In rng
  31. With rCell
  32. iFind = InStr(.Value, sFind)
  33. Do While iFind > 0
  34. .Characters(iFind, iLen).Font.Bold = True
  35. .Characters(iFind, iLen).Font.Color = RGB(255, 0, 0)
  36. .Characters(iFind, iLen).Font.ColorIndex = 4
  37. lCount = lCount + 1
  38. iStart = iFind + iLen
  39. iFind = InStr(iStart, .Value, sFind)
  40. Loop
  41. End With
  42. Next
  43.  
  44. If lCount = 0 Then
  45. MsgBox "Fanns inget" & _
  46. vbCrLf & "' " & sFind & " '" & _
  47. vbCrLf & "att markera"
  48. ElseIf lCount = 1 Then
  49. MsgBox "Det fanns en" & _
  50. vbCrLf & "' " & sFind & " '" & _
  51. vbCrLf & "markerades"
  52. Else
  53. MsgBox lCount & " hittade" & _
  54. vbCrLf & "' " & sFind & " '" & _
  55. vbCrLf & "och markerades"
  56. End If
  57.  
  58. ExitHandler:
  59. Set rCell = Nothing
  60. Set rng = Nothing
  61. Exit Sub
  62.  
  63. ErrHandler:
  64. MsgBox Err.Description
  65. Resume ExitHandler
Add Comment
Please, Sign In to add comment