
Object variable or with block variable not set
This is a excel macro which selects the text within brackets from the
excel sheet and sets the colour to blue.
I am getting a runtime error 91 'Object variable or with block
variable not set'
When I run this macro.
THe complete code for it is as follows:
Sub Q_SetQuestionnairecolors()
'On Error Resume Next
Dim TempRow As Long
Dim strCell As String
Dim strCellData As String
Dim EndOfSheet As Boolean
Dim bolFound As Boolean
Dim iBegin As Integer
Dim iStart As Integer
Dim iEnd As Integer
Range("A1").Select
While Not EndOfSheet
Cells.Find(What:="[", After:=ActiveCell, LookIn:=xlValues,
LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False).Activate
If ActiveCell.Row < TempRow Then
EndOfSheet = True
Else
TempRow = ActiveCell.Row
strCell = ActiveCell.Text
iBegin = 0
While Len(strCell) > 0
If InStr(strCell, "[") > 0 Then
iStart = InStr(strCell, "[")
iEnd = InStr(strCell, "]") - iStart + 1
With ActiveCell.Characters(Start:=iStart + iBegin,
Length:=iEnd).Font
.FontStyle = "Regular"
.ColorIndex = 5
End With
iBegin = iEnd
strCell = Right(strCell, Len(strCell) -
InStr(strCell, "]"))
Else
strCell = ""
End If
Wend
End If
Wend
EndOfSheet = False
Range("A1").Select
While Not EndOfSheet
Cells.Find(What:="{", After:=ActiveCell, LookIn:=xlValues,
LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False).Activate
If ActiveCell.Row < TempRow Then
EndOfSheet = True
Else
TempRow = ActiveCell.Row
strCell = ActiveCell.Text
iBegin = 0
While Len(strCell) > 0
If InStr(strCell, "{") > 0 Then
iStart = InStr(strCell, "{")
iEnd = InStr(strCell, "}") - iStart + 1
With ActiveCell.Characters(Start:=iStart + iBegin,
Length:=iEnd).Font
.FontStyle = "Regular"
.ColorIndex = 5
End With
iBegin = iEnd
strCell = Right(strCell, Len(strCell) -
InStr(strCell, "}"))
Else
strCell = ""
End If
Wend
End If
Wend
End Sub
Please help.
Regards
Elavarasi