Tuesday, November 10, 2009

Search And Bold Text

Sub SearchAndBoldText()
'
' Macro1 Macro
' Macro recorded 11/10/2009 by drai9
'

'
On Error GoTo Err
Dim i As Integer
Dim LastRow As Integer
Dim strt As Integer
Dim col As String
Dim TextToFind As String
Dim TextLen As Integer
TextToFind = Application.InputBox("Please enter the Text you want to find. e.g. Test Objective:")
LastRow = Application.InputBox("Please enter the last row number. e.g. 140")
col = Application.InputBox("Please enter the Column Header name. e.g. A")
TextLen = Len(TextToFind)

For i = 1 To LastRow
Range(col & i).Select
'strt = CInt(Cells(i, 10).Value)
strt = InStr(1, ActiveCell.Text, TextToFind, vbTextCompare)

With ActiveCell.Characters(Start:=strt, Length:=TextLen).Font
.FontStyle = "Bold"
End With
Next

Err:
MsgBox ("Error Number:" & Err.Number & vbNewLine & Err.Description)
End Sub